Rotation using both axis inputs?

Hello. I am trying to make an object's rotation around the y axis be controlled by the player's input on the horizontal and vertical axes (in my case WASD). So if the player is pressing W, the y rotation would be 0 degrees, if the player then pressed A the rotation would go to 45 degrees, if they let go of W, it would go to 90 degrees, etc.

How would I do that?

1 Answer

1
function Update()
{
    var direction = Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical"));
    if (direction.magnitude > 0.2)
    {
        transform.LookAt(transform.position + direction);
    }
}

Not tested, but should work ;)

Maybe you need to invert one or both axis. Just test it and put a "-" in front