Limiting rotation in 2 axis'

I have spent many many hours working on something unsuccessfully and am just shy of given up, I wrote out this question once already and my sleeping girlfriend decided to roll over my mouse and somehow managed to click something that took me back to the sites index, deleting all I had written…

Back on track now: Basically I have lost a whole nights sleep trying to stop my toy darn car in the game i’m making flipping upside down all the blooming time (please insert profanities where seen fit) and I have had 0 success, I’ve tried Mathf.Clamp and Lerp and Slerp and zeroing the rotation whenever the axis rotates over a certain point and now I just want to shoot my laptop.

Anyone who can shed some light on the conclusion on this will forever be my hero… please help…

[Here’s my hours worth of work, as written and unwritten with the backspace]

//logic workings set in scene
public float speed;
public Vector3 startPoint;

//In game items sourced
//private Rigidbody rb;

void Start () {
    //gets the RigidBody to relate to the code
    //rb = GetComponent<Rigidbody>();
}
	
void Update () {
    //Movement control
    if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S))
    {
        transform.position -= transform.forward * Time.deltaTime * speed;
        if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))
        {
            transform.Rotate(0, -2, 0);
        }

        if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
        {
            transform.Rotate(0, 2, 0);
        }
    }
    else
    {
        if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W))
        {
            transform.position += transform.forward * Time.deltaTime * speed;
        }

        if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))
        {
            transform.Rotate(0, 2, 0);
        }

        if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
        {
            transform.Rotate(0, -2, 0);
        }
    }

    //rotation control
    if (transform.localRotation.x > 30 || transform.localRotation.x < -30)
    {
        transform.rotation = Quaternion.Euler(0, transform.rotation.y, transform.rotation.z);
    }
}

Someone please save me from this hell
thanks in advance

  • Dave

I was going to skip that one because too much whining and girlfriend bashing but here it is, now buy her flowers toapologize, you douche.

93024-rb-constraint.png