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

Physics event to know "steady state" #620

Open
rrrepos opened this issue Feb 10, 2024 · 1 comment
Open

Physics event to know "steady state" #620

rrrepos opened this issue Feb 10, 2024 · 1 comment
Labels
question Further information is requested

Comments

@rrrepos
Copy link

rrrepos commented Feb 10, 2024

Hello:

I wish to know if there are events related to the Physics API?

The game that I am creating is: permitting the user to move a ball (using Leva controls) to some position and then releasing it. During movement of the ball, physics is paused and once placed the user releases the ball (causing the physics to unpause). I need to know when all the rigid bodies in the scene have completed their "movements" so that the user can once again move the ball to another position.

For the same I was hoping to have an event that perhaps can "call" that all objects are stationary. Using useframe hampers smoothness.

Thanks.

@wiledal wiledal added the question Further information is requested label Mar 18, 2024
@isaac-mason
Copy link
Member

isaac-mason commented May 22, 2024

Internally @react-three/rapier uses world.forEachActiveRigidBody to invalidate frames when there are active / non-sleeping bodies.

Maybe this is better:

let allBodiesSleeping = true;
for (const body of world.bodies.getAll()) {
  if (!body.isSleeping()) {
    allBodiesSleeping = false;
    break;
  }
}

https://rapier.rs/docs/user_guides/javascript/rigid_bodies/#sleeping

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

No branches or pull requests

3 participants