I have a sidescroller with the camera following the player (Character Controller) along the x axis. Because of this camera angle, I have swapped my inputs to match the actual direction ie:
horizontal is left and right
vertical is down and up
The ability to move the player in all directions is here but I would like to use the fluid motion of:
transform.rotation = Quaternion.LookRotation(moveDirection);
^^^ unfortunately using this method alone leaves my player facing -90 deg of the direction he is traveling…
so…
“right arrow” you get the players butt (which should be his right side)
“left arrow” you get his face (which should be his left side)
Looking for a better implementation of this function below (which works but is choppy as there is no easeing) or a way to get the LookRotation to match my players actual direction:
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection *= speed;
float dirH = Input.GetAxisRaw("Horizontal");
float dirV = Input.GetAxisRaw("Vertical");
if (dirH != 0 && dirV != 0)
{
Debug.Log("TRAVELING AT AN ANGLE");
if (dirV > 0)
{
transform.eulerAngles = (dirH > 0) ? Vector3.up * 135 : Vector3.up * 45;
}
else
{
transform.eulerAngles = (dirH > 0) ? Vector3.up * -135 : Vector3.up * -45;
}
targetSpeed = Input.GetAxisRaw("Horizontal") * speed;
}
else if (dirH != 0)
{
Debug.Log("H");
transform.eulerAngles = (dirH > 0) ? Vector3.up * 180 : Vector3.zero;
targetSpeed = Input.GetAxisRaw("Horizontal") * speed;
}
else if (dirV != 0)
{
Debug.Log("V");
transform.eulerAngles = (dirV > 0) ? Vector3.up * 90 : Vector3.up * -90;
targetSpeed = Input.GetAxisRaw("Vertical") * speed;
}
else
{
targetSpeed = 0;
}
As always, any direction and help is greatly appreciated, so Thanks in advance!