Hello,
I’m trying to figure out, how given input in the horizontal and verticle axis, that I can rotate a player towards that direction using the 2D tools in Unity. So far, from looking around the internet, I have been able to rotate the player but it rotates around every axis except the Z axis. This essentially stops the player from being visible.
private void RotatePlayer()
{
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis ("Vertical");
if( !m_netHandler.IsOwner())
{
horizontal = m_clientLastHorizontalInput;
vertical = m_clientLastVerticalInput;
}
if(horizontal != 0 || vertical != 0)
{
Vector3 desiredDirection = new Vector3(horizontal, vertical);
m_desiredDirection = Quaternion.LookRotation(desiredDirection.normalized);
}
transform.rotation = Quaternion.Slerp(transform.rotation, m_desiredDirection,
Time.deltaTime * m_rotationSpeed);
}
Any ideas would be helpful. Thank you.