how can i rotate player to 90 degrees every time a key is pressed?
I want the player to rotate 90 degrees along y axis, every time right arrow key is pressed. I have tried the following code, and it works, but the only problem that i am facing is that, my player is rotated randomly(random values). moveVector = transform.TransformDirection(Vector3.forward)*speed; //this is for player movement if (Input.GetKey (KeyCode.RightArrow)) { transform.Rotate(0,90,0); // this is for changing direction(rotation) }
So, for example, Key pressed once --> player rotation--90 degrees key pressed 2nd time--> player rotation -- (-180 at times, and at times negative 90-- meaning its not consistent) Sometimes, when i test the game again, and i press the key for the first time, the player is rotated to -180 degrees, and sometimes to -90. So, i feel like unity is may be storing the values somewhere? it is so frustrating :((( somebody pleaaseee explain this to me!!