[Here][1] is an example of what I am trying to accomplish that I found when trying to find a solution
I am attempting to make a third person character controller with 8 direction movement where the character rotates towards the direction that it is moving, while also using the mouse to control it's direction. For example, when walking forwards, the character will walk away from the camera. When walking sideways, they will walk towards the left or the right of the camera and towards the camera if backwards.
Here is what I currently have:
Vector3 movementDirection = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
if (movementDirection != Vector3.zero)
{
// This works to make the character move towards the direction of the camera
this.transform.rotation = Quaternion.Euler(0, mainCamera.transform.rotation.eulerAngles.y , 0);
// This works to rotate the character in the direction of it's movement
this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(movementDirection), 0.15f);
}
I feel like adding the camera's rotation to the Quaternion.LookRotation is what I need to do but I am not sure how to go about this.
[1]: https://www.youtube.com/watch?v=Hp4jQgGEZfI
↧