Get Total Rotation of Wheel Collider

Hi. I’m using a wheel collider car to simulate autonomous movement in a wheeled robot. I want to simulate an encoder on the wheel collider. Is it possible to get the total degrees traveled by a wheel collider? For example, if the robot were to drive forward enough for the wheel to rotate two times, how could I get an output of 720 degrees from that?

Thanks for all the help.

There’s no built in rotation counter, but we can keep track of it ourselves using the wheel’s RPM;

private float totalRotations = 0f;

void LateUpdate ()
{
    //Find the current RPM and convert to rotations per second
    float rps = wheel.rpm / 60f;
    //Scale by time since the last frame and add to total
    totalRotations += rps * Time.deltaTime;

    //Just multiply by 360 to convert to degrees
    float totalDegrees = totalRotations * 360f;
    visual.localRotation = Quaternion.Euler (new Vector3 (totalDegrees, 0f, 0f));
}