This project has moved and is read-only. For the latest updates, please go here.

Velocity of a body and velocity limitation?

Topics: User Forum
Dec 15, 2013 at 7:39 PM
Edited Dec 15, 2013 at 7:39 PM
I want to know how fast my body(a circle) is moving. How can I do that? How can I measure the velocity of a body?
In addition, I want to limit the velocity of a body. For example, I want that a body couldn't move with more than 50 km/h. How can I do that?
Dec 17, 2013 at 9:18 PM
Problem solved:
float maxSpeed = 50 / 3.6f; //50km/h -> m/s
float maxSpeedSquared = maxSpeed * maxSpeed;
float len2 = myBody.LinearVelocity.LengthSquared();
if(len2 > maxSpeedSquared)
    float len = (float)Math.Sqrt(len2);
    myBody.LinearVelocity = myBody.linearVelocity * (1f/len) * maxSpeed