[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.