I’m trying to make my character rotate 90 degrees each time a player presses an arrow key, but I’m having trouble with the rotation. Currently, the player moves extremely quickly between -90, 90, and 180. My code is below. if anyone can help me understand why this approach isn’t working and what would be a better approach, I’d greatly appreciate it.
public class PlayerMovement : MonoBehaviour {
void Update()
{
float h = Input.GetAxisRaw ("Horizontal");
if (h != 0)
{
Turn ();
}
}
void Turn ()
{
Vector3 angles = transform.eulerAngles;
float y = angles.y + 90;
transform.rotation = Quaternion.AngleAxis(y, Vector3.up);
}
}