Rotating Player relative to Camera Rotation

Hey there, I’m sure this is a simple one but I cannot wrap my head around it. Basically, I have a 3D 3rd Person game, and these objects:

  1. Player that can move on X and Z,
  2. Camera Rig that follows player and can be rotated on Y
  3. Main Camera attached to Camera Rig

I’ve managed to have the player move using the horizontal and vertical input-axis relative to the camera rotation, but now I want him to rotate accordingly as well. I’m just not sure what values to mix to get it done - ideally, I would want the player to not just jump into the correct rotation, but actually have him gradually rotate there. I appreciate any solutions, ideas and nods into the right direction, pun not intended. Thanks in advance!

Here be the code for the Player:

Rigidbody rb;

float hAxis; //Input Horizontal Axis
float vAxis; //Input Vertical Axis

public GameObject camRig;
Transform camRot; //Y-rotation of camera

public float moveSpeed;

void Start () {
	rb = GetComponent<Rigidbody> ();
	camRot = camRig.transform;
}

void Update () {
	hAxis = Input.GetAxis ("Horizontal");
	vAxis = Input.GetAxis ("Vertical");

	transform.Translate (
		camRot.forward * vAxis * moveSpeed * Time.deltaTime+
		camRot.right*hAxis*moveSpeed*Time.deltaTime, 
		Space.World);

	// Rotating when moving
	if (hAxis != 0 || vAxis != 0){

		//Code for rotating the player when he is in movement goes here

	}

}

Hey there!
I would check out this tutorial to get your rotation working, since it goes hand in hand with what you’re
trying to accomplish:


Hope this helps!

I’d recommend using a tweening engine such as DOTween which makes it easy to set up simple animations through code. Using DOTween you’d be able to call .DoRotate(angle, duration)on the object you want to rotate, having it animate smoothly instead of jumping.