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?
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
}
The other method is to check if the speed is less than 0.001 (or some other small number)
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.
@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.