## How to get the velocity of rigid body

water
Posts: 29
Joined: Fri Jun 05, 2020 8:36 am

### How to get the velocity of rigid body

I want to get the velocity of a rigid body in motion. How can I get it? Thank you very much.
drleviathan
Posts: 653
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

### Re: How to get the velocity of rigid body

water
Posts: 29
Joined: Fri Jun 05, 2020 8:36 am

### Re: How to get the velocity of rigid body

Thank you very much, but the return value I get is btVector3, how can I convert it to speed?
drleviathan
Posts: 653
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

### Re: How to get the velocity of rigid body

Speed is the magnitude of velocity --> compute the length of the btVector3.
water
Posts: 29
Joined: Fri Jun 05, 2020 8:36 am

### Re: How to get the velocity of rigid body

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
drleviathan
Posts: 653
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

### Re: How to get the velocity of rigid body

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``````