Cannot Make Spheres Fall with Physics Framework in A-Frame

I’m working on a simple A-Frame scene where I want to generate spheres that fall and interact with the environment using the physics system. However, the spheres I generate are not falling as expected. Here’s my code:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Physics Sphere Generator</title>
  <script src="https://aframe.io/releases/1.6.0/aframe.min.js"></script>
  <script src="https://cdn.jsdelivr.net/gh/n5ro/[email protected]/dist/aframe-physics-system.min.js"></script>
  <script>
    AFRAME.registerComponent("spheregenerator", {
      init: function () {
        let button = this.el;
        button.addEventListener("click", () => {
          let scene = document.querySelector("#scene");
          let newSphere = document.createElement("a-sphere");

          newSphere.setAttribute("color", "yellow");
          newSphere.setAttribute("scale", "0.3 0.3 0.3");

          let newX = Math.random() * 2 - 1;
          newSphere.setAttribute("position", `${newX} 2 -3`);
          newSphere.setAttribute("dynamic-body", "shape: sphere");

          scene.appendChild(newSphere);
        });
      },
    });
  </script>
</head>
<body>
  <a-scene id="scene" physics="debug:true">
    <a-camera><a-cursor></a-cursor></a-camera>
    <a-plane static-body color="grey" rotation="-90 0 0" scale="15 15 15"></a-plane>
    <a-box spheregenerator color="red" scale="0.5 0.5 0.5" position="2 0.2 -4"></a-box>
  </a-scene>
</body>
</html>

I’ve registered a custom component called spheregenerator that generates a new sphere and sets its dynamic-body attribute to make it interact with the physics system. The spheres are created and appear in the scene, but they do not fall due to gravity as expected.

What could be the reason for the spheres not falling? How can I ensure that the generated spheres will have proper physics and fall due to gravity?

Additional Information:

I’m using A-Frame 1.6.0 and aframe-physics-system 4.0.1.
The debug: true mode for physics shows no errors in the console.
Any help or pointers would be greatly appreciated!

I added a click event listener to generate spheres with the dynamic-body attribute for physics. I expected the spheres to fall due to gravity when generated, but they remain stationary in mid-air. Despite setting the dynamic-body attribute, they do not interact with the physics system as expected. I also tried adjusting the positions and checking the console for errors but found none.

New contributor

Aayan Rahman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật