- Home /
Clamp gyro rotation
Hi everyone,
I'm using the gyroscope input to rotate an object and I'm trying to clamp the rotation of the camera on x and y axis. I'm using the tranform.forward to do that, and it works, but when transform.forward reach that limit values, camera starts to tremble and i'm not happy with the results, it's not smooth. Any better way to clamp the rotation? The following script is a component of an empty object, parent of the main camera. Thank you.
void Update()
{
if (!gyroEnabled)
return;
trigger = transform.forward;
if (trigger.x <= 0.707f && trigger.x >= -0.707f && trigger.y <= 0.707f && trigger.y >= -0.707f)
{
transform.rotation = Quaternion.Slerp(transform.rotation,
cameraBase * (ConvertRotation(referanceRotation * Input.gyro.attitude) * GetRotFix()), lowPassFilterFactor);
}
else
{
transform.forward = new Vector3 (Mathf.Clamp(trigger.x, -0.707f, 0.707f), Mathf.Clamp(trigger.y, -0.707f, 0.707f), 1);
}
}
Comment