Detect if element is moving

Hello!

I am writing a simple billiards game. I want to detect if an element is moving or it just has stopped. Basically, I want to check if an element has kinematic energy. Is there any method in the engine for checking this?

I am asking because I see that collision shape is changing color in debug mode when my object stops moving.

Thank you :slight_smile:

Yeah - RigidBody->GetLinearVelocity is what I need probably :stuck_out_tongue:

Note that:
a) LinearVelocity is a Vector3, you can use its Length() as a velocimeter.
b) Alternatively could use RigidBody::IsActive() in your situation which will return true if either its linear or angular velocity are above their respective thresholds.
c) Welcome to the forums! :confetti_ball: :slight_smile:

Also note that if you donโ€™t actually need the length but a metric to compare against, use Vector3::LengthSquared() to save a call to sqrt()

2 Likes

My game is just a simple learning project and I didnโ€™t measure the performance of LengthSquared but comparing Vector to Vector::ZERO should not be much slower and maybe it is even faster :thinking: I am rather new to cpp and it is not the time for optimization :smile: Anyway both solutions will work just fine :slight_smile: