In a project i have a player with clamped head movement around vertical axis [-85, 85] I need to rotate head to specific direction, but the head keeps facing down all the time, what I'm doing wrong?
I apply rotation to head using separate vector axisViewCamera
:
cameraBody.localRotation = Quaternion.Euler(axisViewCamera);
Clamping: axisViewCamera.x = Mathf.Clamp(axisViewCamera.x, -85f, 85f);
Then i take direction from Transform.forward or calculating it from two Transforms and applying it like this, with help of the DOTween:
var euler = Quaternion.LookRotation(direction, Vector3.up).eulerAngles;
var original = Quaternion.LookRotation(axisViewCamera, Vector3.up).eulerAngles;
blockViewChange = true;
DOTween.To(SetAxis, 0f, 1f, 1).SetTarget(playerCamera)
.OnComplete(() => blockViewChange = false).SetUpdate(true);
void SetAxis(float t) => axisViewCamera = Vector3.Lerp(orig, euler, t);