Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic body without gravity #34

Open
vincentfretin opened this issue Mar 6, 2025 · 0 comments
Open

Dynamic body without gravity #34

vincentfretin opened this issue Mar 6, 2025 · 0 comments

Comments

@vincentfretin
Copy link
Member

vincentfretin commented Mar 6, 2025

I just did something quite complex to create a dynamic body without gravity, and then apply gravity when I grab it so it falls when I release it.

boxEl.setAttribute("physx-body", "type: dynamic");
boxEl.setAttribute("toggle-physics", "");
boxEl.addEventListener("componentinitialized", (evt) => {
  if (evt.detail.name !== "physx-body") {
    return;
  }
  boxEl.components["physx-body"].physxRegisteredPromise.then(() => {
    boxEl.components["physx-body"].toggleGravity();
  });
});
boxEl.addEventListener(
  "pickup",
  () => {
    boxEl.components["physx-body"].toggleGravity();
  },
  { once: true }
);

The pickup event is emitted by grab-magnet-target component (from handy-controls) that toggles the grabbed state if using toggle-physics component that set the kinematic flag

physx/src/physics.js

Lines 953 to 958 in a1271b4

events: {
stateadded: function(e) {
if (e.detail === 'grabbed') {
this.rigidBody.setRigidBodyFlag(PhysX.PxRigidBodyFlag.eKINEMATIC, true)
}
},

Instead of componentinitialized listener and using internal physxRegisteredPromise variable, we should probably add an applyGravity property to physx-body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant