I know there are countless threads on this topic but after hours of research I haven’t found anything I need.
So I wanted to ask you, how can I rotate the player in the direction of the camera?
using RotateTowards the player rotates according to an angle in speed * time but each rotation angle is different from each other and therefore the step it performs means that sometimes the player does not get a complete rotation towards the camera.
so what I’m looking for is to instantly rotate the player in the direction of the camera when it moves
“precise I want the player to rotate only if the camera is at a different angle and when moved it goes in that direction”
not that by rotating the camera the player rotates simultaneously
this is my reference code.
_xRotation += Mouse_X * sensX * Time.smoothDeltaTime;
_yRotation += -Mouse_Y * sensY * Time.smoothDeltaTime;
_yRotation = Mathf.Clamp(_yRotation, upperLimit, bottomLimit);
Vector3 Direction = new Vector3(0, 0, -distance);
Quaternion rotation = Quaternion.Euler(_yRotation, _xRotation, 0);
_mainCamera.transform.position = lookPos + rotation * Direction;
_mainCamera.transform.LookAt(lookPos);
if (_inputManager.Move != Vector2.zero)
{
//I would like to get rid of all this code flow
Vector3 movement = new Vector3(_inputManager.Move.x, 0, _inputManager.Move.y);
Vector3 camDirection = _mainCamera.transform.TransformDirection(movement);
camDirection.y = 0;
camDirection.Normalize();
Vector3 desiredForward = Vector3.RotateTowards(transform.forward, camDirection, RotationSpeed * Time.smoothDeltaTime, 0f);
transform.rotation = Quaternion.LookRotation(camDirection);
//up to here
}
}