Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

box2d: GetLinearVelocity() to detect motion?

Tags:

box2d

Pretty simple question: will the result of b2Body::GetLinearVelocity tell me if an object is in motion? I would expect that it would - does it?

like image 350
Rob Avatar asked Dec 08 '25 10:12

Rob


2 Answers

GetLinearVelocity() returns a b2Vec2. You could use b2Vec2::Length() to find the magnitude of the velocity; if it is zero, the object is not moving.

like image 182
Cory G. Avatar answered Dec 12 '25 05:12

Cory G.


It would tell you if the body is moving. However it could also happen to be spinning in one place around the origin and getLinearVelocity() would return zero. So if you want to be definitely sure that no motion is happening you should check getAngularVelocity() as well.

like image 25
Justas Sakalauskas Avatar answered Dec 12 '25 05:12

Justas Sakalauskas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!