Value of velocity

Official forum for the Chipmunk2D Physics Library.
Post Reply
akamal
Posts: 15
Joined: Fri Mar 11, 2011 3:32 pm
Contact:

Value of velocity

Post by akamal »

I want to calculate current velocity of a body in m/s and its acceleration. How should I do that
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Value of velocity

Post by slembcke »

Chipmunk doesn't have any explicit units. Generally people just use 1 unit = 1 pixel. Time also doesn't have explicit units, but I can't really imagine anybody using anything other than seconds really.

If you create your objects assuming that 1 unit = 1 meter, then the units of the cpBody.v field will be in meters/second. If you want to calculate the acceleration, you'll have to store the velocity from the last frame and do some numerical differentiation to estimate it. Basically just (speedThisFrame - speedLastFrame)/timeStep.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
akamal
Posts: 15
Joined: Fri Mar 11, 2011 3:32 pm
Contact:

Re: Value of velocity

Post by akamal »

cpBody.v is a vector (value is according to x y). How Can I get a single value in float.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Value of velocity

Post by slembcke »

cpvlength(body->v)
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
akamal
Posts: 15
Joined: Fri Mar 11, 2011 3:32 pm
Contact:

Re: Value of velocity

Post by akamal »

Thanks :)
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests