- Home /
Calculating turning radius of a rigidbody
I have a rigidbody in 3D space that I want to calculate the turning radius of in the XZ plane (so about the Y axis). I'm able to easily get the Y component of the angular velocity of the object via scripting, and I'm getting values of around 0.05 which "look realistic." I'd like to have a similar readout of calculated turning radius so I can ensure I'm simulating the object correctly. The specification of the object is in terms of turning radius.
I feel like there should be a way to calculate turning radius from angular velocity or from some other statistic of the rigidbody. I'm having difficulty visualizing this.
As a side note, this 0.05 is a scalar rotation around the Y axis. What does this number actually mean, however, in terms of units? Is it degrees or radians per unit time or similar?
Answer by _alphaBeta_ · May 29, 2015 at 03:31 PM
I ran this down and got my head around it. The scalar rotation represents radians / sec best I can tell. In short, I just needed to divide the forward velocity by the angular velocity to yield the radius of movement. Simple enough and confirmed in-game.
Standard physics: The tangential velocity (Vt) can be calculated from the product of the angular velocity (w) and the radius of the motion (r).
Vt = w * r
In my case, I obviously want the radius. Furthermore in my example, since the rotation of the rigidbody itself matches the angle of movement around this circle of unknown radius (the turning radius I'm trying to find), I can use both the angular velocity and forward velocity of the rigidbody as calculated by Unity and solve the equation.
r = Vt / w
To think of this another way, consider the picture below and visualize the setup as a wheel with my rigidbody on the edge. We're looking from the top down along Y in the negative world direction here. The rigidbody's forward is along local x transform.
In code, I can simply do the following to compute the turn radius:
public Vector3 angularVelocity;
public float turningRadius;
void FixedUpdate ()
{
angularVelocity = rb.angularVelocity;
turningRadius = getVelocity() / angularVelocity.y;
}
public float getVelocity ()
{
Vector3 dir = -gameObject.transform.right;
return Vector3.Dot(rb.velocity, dir);
}