Page 1 of 1
Value of velocity
Posted: Fri Mar 11, 2011 3:34 pm
by akamal
I want to calculate current velocity of a body in m/s and its acceleration. How should I do that
Re: Value of velocity
Posted: Fri Mar 11, 2011 7:56 pm
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.
Re: Value of velocity
Posted: Sat Mar 12, 2011 8:58 pm
by akamal
cpBody.v is a vector (value is according to x y). How Can I get a single value in float.
Re: Value of velocity
Posted: Sat Mar 12, 2011 9:51 pm
by slembcke
cpvlength(body->v)
Re: Value of velocity
Posted: Mon Mar 14, 2011 1:33 pm
by akamal
Thanks