# Move and rotate character relative to camera

I’m trying to make something like the system in the 3D Zelda games but can’t figure out how to make the player rotate towards their move direction relative to the camera.

This is what i currently use to make them always face forward from the camera when moving.

``````void SnapAlignWithCamera()
{
if (MoveVector.x != 0 || MoveVector.z != 0)
{
transform.rotation = Quaternion.Euler (transform.rotation.eulerAngles.x, Camera.main.transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z);
}
}
``````

How can i make it to where they still move relative to the camera but face their move direction?

Having a little trouble understanding this. Can you explain a little more?

Actually i manged to find a solution to this code. What it simply did was IF the character was moving along is X or Z axis it would snap to face the forward direction of the Main Camera.

But this code makes so it faces the direction its moving relative to it.

``````public void RotateTowardsMoveDirection(Vector3 direction)
{
Vector3 cameraDirection = Camera.main.transform.rotation * direction;
Vector3 currentDirection = transform.position + cameraDirection;

Quaternion targetRotation = Quaternion.LookRotation (currentDirection - transform.position);
Quaternion constrained = Quaternion.Euler (0, targetRotation.eulerAngles.y, 0);

transform.rotation = Quaternion.Slerp (transform.rotation, constrained, Time.deltaTime * Smooth);

//if (MoveVector.x != 0 || MoveVector.z != 0)
//transform.rotation = Quaternion.Euler (transform.rotation.eulerAngles.x, Camera.main.transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z);
}
``````

However, now this code makes the character move relative to the direction its facing in, not relative to the camera.

In the order of the attached pictures, this is what the previous code did with the SnapAlignWithCamera(), what it does now with the RotateTowardsMoveDirection(), and what i want it to do.