dimforge / rapier

2D and 3D physics engines focused on performance.
https://rapier.rs
Apache License 2.0
3.93k stars 244 forks source link

Stop a rigid body #448

Open APerricone opened 1 year ago

APerricone commented 1 year ago

Hi, In my project I would like reuse some rigid body, so stop them, move and sleep, I tried with:

reset(world :World) {
    let collider = world.getCollider(this.colliderId);
    let rigidBody = collider.parent()!;
    rigidBody.setTranslation(new Vector2(0,settings.ballHeight), false);
    rigidBody.setNextKinematicTranslation(new Vector2(0,settings.ballHeight));
    rigidBody.setRotation(0, false);
    rigidBody.setNextKinematicRotation(0);
    rigidBody.resetForces(false);
    rigidBody.resetTorques(false);
    rigidBody.sleep();
}

But it is still awake. It is TypeScript but I think the same issue is present with javascript and rust. I am using the 0.11.1

APerricone commented 1 year ago

it is strange, If I call only sleep the rigid body stops, but If I try to move it it wake up without possibility of keep it asleep

LukeCarlThompson commented 1 year ago

I'm having the same issue. I'm not able to find a way of repositioning a rigid body and setting it to sleep on the same frame.

The work around I've been doing is moving the rigid body off screen and then calling .sleep() on it in a setTimeout. I still find I have to make sure the sleeping objects don't get moved into the same position off screen because then they wake each other up again.

I'm using 0.11.2

Would love a solution for this.