Here is my code for moving in four main directions:
if (Input.GetKeyDown(KeyCode.RightArrow)){ transform.forward = new Vector3(0f, 0f, 1f); } else if (Input.GetKeyDown(KeyCode.LeftArrow)){ transform.forward = new Vector3(0f, 0f, -1f); } else if (Input.GetKeyDown(KeyCode.DownArrow)){ transform.forward = new Vector3(1f, 0f, 0f); } else if (Input.GetKeyDown(KeyCode.UpArrow)){ transform.forward = new Vector3(-1f, 0f, 0f); }
My character instantly rotates in four directions of travel. The problem I am facing is figuring out how I can smooth out intermediate directions. I'm trying to say if the character points to the north, and you press the button to go west, and not immediately turn to the west, I would like the character to smoothly rotate in degrees towards the west.
I searched and tried textbooks, but none of them worked. Any solution?
source share