Page 1 of 1

How to get the velocity of rigid body

Posted: Thu Jul 09, 2020 1:43 am
by water
I want to get the velocity of a rigid body in motion. How can I get it? Thank you very much.

Re: How to get the velocity of rigid body

Posted: Thu Jul 09, 2020 3:15 am
by drleviathan

Re: How to get the velocity of rigid body

Posted: Mon Jul 13, 2020 6:43 am
by water
Thank you very much, but the return value I get is btVector3, how can I convert it to speed?

Re: How to get the velocity of rigid body

Posted: Mon Jul 13, 2020 2:25 pm
by drleviathan
Speed is the magnitude of velocity --> compute the length of the btVector3.

Re: How to get the velocity of rigid body

Posted: Tue Jul 28, 2020 3:38 am
by water
This seems to be the speed of each frame. What should I do if I want to get the speed per second? Thank you for your time

Re: How to get the velocity of rigid body

Posted: Tue Jul 28, 2020 2:56 pm
by drleviathan
speed = deltaDistance / deltaTime = meters /second

acceleration = deltaSpeed / deltaTime = meters / second^2

There is no RigidBody::getLinearAcceleration() method in the API.

There is a RigidBody::getGravity() method which would provide the free-fall acceleration sans collisions.

To measure the true effective acceleration of the object you must do it manually, which would require you to remember the lastTime and lastVelocity from the previous measurement. In pseudo code it might look something like:

Code: Select all

thisTime = getTimeNow()
thisVelocity = getLinearVelocity()
deltaVelocity = thisVelocity - lastVelocity
deltaTime = thisTime - lastTime
acceleration = deltaVelocity / deltaTime
lastTime = thisTime
lastVelocity = thisVelocity