[SOLVED] Check if RigidBody has stopped

Is there an inbuilt way of checking whether a rigid body has stopped moving?

Do I need to do it the long way and compare successive positions until the difference is within a certain threshold to zero?

Hi @Jimage,

Yes there is a way, to check if a dynamic body is still active that means itā€™s still moving and hasnā€™t ā€œsleptā€:

if (entity.rigidbody.isActive() === true){
   // body is still moving
}
1 Like

The other method is to check if the speed is less than 0.001 (or some other small number)

2 Likes

Ohh, right. I would have guessed ā€˜activeā€™ meant something more general and might still return true if it wasnā€™t moving.

I couldnā€™t figure out how to actually get the speed itself. I thought it might be linearVelocity but that was returning very non-zero numbers while stationary.

Iā€™ve been networking a physics based game and isActive() seems to work quite nice to detect when an object is moving and needs to have its state networked.

1 Like

@Jimage, to use linear velocity values you can do a check:

entity.rigidbody.linearVelocity.lengthSq() > 0.0001 // moving
entity.rigidbody.angularVelocity.lengthSq() > 0.0001 // rotating

That will come in handy. I had found reference to the lengthSq but must have mashed it into my code incorrectly when I tried it out.