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
|
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.
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.
The
pickupevent is emitted bygrab-magnet-targetcomponent (from handy-controls) that toggles thegrabbedstate if using toggle-physics component that set the kinematic flagphysx/src/physics.js
Lines 953 to 958 in a1271b4
Instead of
componentinitializedlistener and using internalphysxRegisteredPromisevariable, we should probably add anapplyGravityproperty tophysx-body.