Search Unity

How to limit the Rotation of an object to 45 degrees.

Discussion in 'Physics' started by Broken-Beans, Mar 6, 2015.

  1. Broken-Beans

    Broken-Beans

    Joined:
    Mar 27, 2014
    Posts:
    1
    Hello, I am building a car simulator for a school project and I want to make a steering wheel, the only problem is that it rotates too much and I need to limit it. Please help me!
    Here is for rotating the wheel.
    Code (JavaScript):
    1.     public var moveSpeed : float = 10f;
    2. public var turnSpeed : float = 50f;
    3.  
    4. function Update ()
    5. {
    6.  
    7.  
    8.     if (Input.GetAxis ("Horizontal") ==-1)
    9.  
    10. transform.Rotate(Vector3(0,0,a), -turnSpeed * Time.deltaTime);
    11.  
    12.     if (Input.GetAxis ("Horizontal") ==1 )
    13.             transform.Rotate(Vector3.forward, -turnSpeed * Time.deltaTime);