Search Unity

Clamp rigidbody.MoveRotation

Discussion in 'Physics' started by MathewHI, Mar 9, 2019.

  1. MathewHI

    MathewHI

    Joined:
    Mar 29, 2016
    Posts:
    501
    Is it possible to clamp rigidbody.MoveRotation? I followed the unity tank tutorial and I really like the controls but I would like to clamp moverotation 30 degrees left and right as I'm using it for tire rotation on a race car. I tried Mathf.Clamp but it didn't do anything. Any help will be appreciated.
     
  2. MathewHI

    MathewHI

    Joined:
    Mar 29, 2016
    Posts:
    501
    I figured out how to clamp the tires

    float rotation = Input.GetAxis("Horizontal");
    frontLeft.localEulerAngles = new Vector3(0, rotation * 30, 0);
    frontRight.localEulerAngles = new Vector3(0, rotation * 30, 0);