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

Loss of determinism when using collider.setRotationWrtParent or rigidBody.setRotation #797

Open
monteiz opened this issue Feb 7, 2025 · 0 comments

Comments

@monteiz
Copy link

monteiz commented Feb 7, 2025

I have observed that the Rapier.js physics simulation loses determinism when using the collider.setRotationWrtParent and rigidBody.setRotation methods. Specifically, even when starting from the same initial state (restored via World.restoreSnapshot), the simulation outcomes differ every time these methods are applied. This behavior does not occur when only restoring the world snapshot without applying these methods.

Steps to Reproduce

  1. Restore the world from a snapshot:
 const world = RAPIER.World.restoreSnapshot(base64ToUint8Array(worldData.world));
  1. Apply one of the following methods:
  • For a rigid body:
const rigidBody = world.rigidBodies.get(rigidBodyHandle);
rigidBody.setRotation(0); // Breaks determinism
  • For a collider:
const collider = world.colliders.get(colliderHandle);
collider.setRotationWrtParent(0); // also breaks determinism, even when the collider is already attached to a rigid body. This behavior contradicts the documentation, which states: "Does nothing if this collider isn't attached to a rigid-body." However, based on my observations, the method appears to have an effect even when the collider is attached, potentially introducing non-deterministic behavior.
  1. Run the simulation multiple times and observe that the results differ each time.

Expected Behavior

The simulation should produce identical results every time it is run from the same initial state, regardless of whether collider.setRotationWrtParent or rigidBody.setRotation is used.

Actual Behavior

When collider.setRotationWrtParent or rigidBody.setRotation is called, the simulation outcomes vary between runs, breaking determinism.

Environment

  • Rapier.js version: @dimforge/rapier2d-compat 0.14.0
  • Browser: Chrome 132.0.6834.162 (Official Build) (x86_64)
  • Operating System: macOS

Additional Notes

It seems that these methods might introduce non-deterministic behavior due to floating-point precision issues or internal state changes that are not synchronized properly. This could be related to how the physics engine handles rotations internally.

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