rapier.js icon indicating copy to clipboard operation
rapier.js copied to clipboard

Unable to retrieve locked rotation and locked translation state of a created rigid body

Open iamarkdev opened this issue 1 year ago • 3 comments

I've dug through the docs and the type definition files, I need to determine the current rotation and translation lock state of an a rigid body that has already been added to the simulation (RigidBody, not RigidBodyDesc).

There does not seem to be a way to get this information from the RigidBody type. Is this intentional or a feature not yet supported in the JS / TS api?

iamarkdev avatar Sep 10 '24 20:09 iamarkdev

I've dug through the docs and the type definition files

?

https://rapier.rs/javascript3d/classes/RigidBody.html#translation https://rapier.rs/javascript3d/classes/RigidBody.html#rotation

LeXXik avatar Sep 10 '24 21:09 LeXXik

I've dug through the docs and the type definition files

?

https://rapier.rs/javascript3d/classes/RigidBody.html#translation https://rapier.rs/javascript3d/classes/RigidBody.html#rotation

This is the rotation and translation vector/quat, not if translations or rotations for a given axes are locked. I need to know what axes for rotations and translations are locked.

iamarkdev avatar Sep 10 '24 21:09 iamarkdev

I recommend you keep your rigidBodyDesc and rigidBody components together in an "Entity" class so you can access their properties after being created. Here is an example I've created for storing the components in an Entity class: https://github.com/doppl3r/kinematic-character-controller-example/blob/master/src/js/entities/Entity.js

The "locked" or "enabled" states are stored in the rigidBodyDesc object and can be accessed directly:

// Locked translation states
rigidBodyDesc.translationsEnabledX;
rigidBodyDesc.translationsEnabledY;
rigidBodyDesc.translationsEnabledZ;

// Locked rotation states
rigidBodyDesc.rotationsEnabledX;
rigidBodyDesc.rotationsEnabledY;
rigidBodyDesc.rotationsEnabledZ; 

You can modify these by running these functions:

rigidBodyDesc.enabledRotations(true, true, true);
rigidBodyDesc.enabledTranslations(true, true, true);

doppl3r avatar Sep 10 '24 21:09 doppl3r