- Home /
Question by
ttdburnout · Jul 08, 2016 at 11:29 AM ·
rotationanglesquaternions
Clamp Rotation of an object depending of the Rotation of an other one
Hi, I'm trying to limit the pan and tilt of the head of a character without limiting the camera. I'd like the player to be able to move the camera as much as he wants but I don't want the Head of the character to follow the rotation if it goes over a certain angle.
This is my code so far, it's not working great:
void Update()
{
float angleX = 0f;
float angleY = 0f;
if (!isLocalPlayer)
{
return;
}
angleX = Mathf.Abs(head.CameraTransform.localRotation.x);
angleY = Mathf.Abs(head.CameraTransform.localRotation.y);
if (angleX < 0.3f)
tHead.localEulerAngles = new Vector3(head.CameraTransform.eulerAngles.x, tHead.localEulerAngles.y, tHead.localEulerAngles.z);
if (angleY < 0.7f)
tHead.localEulerAngles = new Vector3(tHead.localEulerAngles.x, head.CameraTransform.eulerAngles.y, tHead.localEulerAngles.z);
}
Any help is welcome.
Comment