I’m making a infinite runner. My character is already moving forward by itself.
This is the code i have to the rotation (on Update):
moveDirection.x = Input.GetAxisRaw (“Horizontal”) * runningSpeed;
if (Input.GetKey (KeyCode.LeftArrow)) {
transform.eulerAngles = new Vector3 (0, -45, 0);
}
if (Input.GetKeyUp (KeyCode.LeftArrow))
transform.eulerAngles = Vector3.zero;
if (Input.GetKey (KeyCode.RightArrow)) {
transform.eulerAngles = new Vector3 (0, 45, 0);
}
if (Input.GetKeyUp (KeyCode.RightArrow))
transform.eulerAngles = Vector3.zero;
Now, what i would like to see is making the rotation smooth. I don’t understand quite the Quaternions.
Thanks, in advance!
@Nomenokes Thanks, it works when the key is pressed, but not when i release the key! On the return, it's supposed to be like this, right? transform.rotation = Quaternion.Lerp (transform.rotation, Quaternion.Euler (0, 0, 0), speed);
– andre_95