Hey there! So I have tried to make my Character Rotate when I am walking around with Vertical and Horizontal Axis. Though the closest I got to make it work was this script. Though my only problem with the script is that when I stop moving it resets it self by looking the same direction as when I spawn the player. Anyone who knows why?
using UnityEngine;
using System.Collections;
public class MoveLook : MonoBehaviour {
public float lookSpeed = 10;
private Vector3 curLoc;
private Vector3 prevLoc;
void Update ()
{
InputListen();
transform.rotation = Quaternion.Lerp (transform.rotation, Quaternion.LookRotation(transform.position - prevLoc), Time.fixedDeltaTime * lookSpeed);
}
private void InputListen()
{
prevLoc = curLoc;
curLoc = transform.position;
if (Input.GetKey (KeyCode.A))
curLoc.x -= 1 * Time.fixedDeltaTime;
if (Input.GetKey (KeyCode.D))
curLoc.x += 1 * Time.fixedDeltaTime;
if (Input.GetKey (KeyCode.W))
curLoc.z += 1 * Time.fixedDeltaTime;
if (Input.GetKey (KeyCode.S))
curLoc.z -= 1 * Time.fixedDeltaTime;
transform.position = curLoc;
}
}