Make character face movement direction
Hello, I have a scene with a non-moving camera which is always looking at my character (rotating). I have the following script for the camera rotation:
void LateUpdate()
{
LookAtPlayer();
}
void LookAtPlayer()
{
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(player.transform.position - transform.position), rotationSpeed * Time.deltaTime);
}
I'm currently using the following script to achieve character movement. The movement itself is working perfectly fine but my character does not always look at the direction of it's movement and I have no clue how to achieve this behaviour.
void Update()
{
moveHorizontal = Input.GetAxis("Horizontal");
moveVertical = Input.GetAxis("Vertical");
Vector3 moveDirection = new Vector3(Camera.main.transform.right.x * moveHorizontal, 0f, Camera.main.transform.forward.z * moveVertical);
if(moveDirection != Vector3.zero)
{
Quaternion newRotation = Quaternion.LookRotation(moveDirection);
transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * 8);
}
}
Can you help me out?
Comment
Your answer
Follow this Question
Related Questions
Change Camera's size relative to player's speed 0 Answers
How to make character rotate in direction of movement? 1 Answer
How to access y rotation of an object as a variable or value 1 Answer
Camera looking at the player at an angle 1 Answer
Problems with rotating the player on the Y axis C# 0 Answers