- Home /
Question by
sr3ds · Dec 17, 2015 at 10:46 AM ·
gyroscopeclamped rotation
Clamping a quaternion slerp on gyro
Hi, I´m trying to clamp the rotation of a gyroscope, but i´m not sure if i´m using the correct logic because i get some strange behaviours instead of the supposed block at the desired point.
i read that i need to work on eulerangles to do that and that´s what i basically tried with no success.
Here is my update, is more ore less everything in, and variables not defined are pretty self explanatory:
protected void Update()
{
if (!gyroEnabled)
return;
var gyroInput = Input.gyro.attitude;
Quaternion newRotation = Quaternion.Slerp(transform.rotation,
cameraBase*(ConvertRotation(referanceRotation*gyroInput)*GetRotFix()), lowPassFilterFactor);
var eulerX = newRotation.eulerAngles.x;
var eulerY = newRotation.eulerAngles.y;
var eulerZ = newRotation.eulerAngles.z;
eulerX = ClampAngle(eulerX, minPitch, maxPitch);
eulerY = ClampAngle(eulerY, minYaw, maxYaw);
Vector3 finalRotation = new Vector3(eulerX, eulerY, eulerZ);
newRotation = Quaternion.Euler(finalRotation);
transform.rotation = newRotation;
}
thanks to eveyone in advance.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612052952im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Clamp gyro rotation 0 Answers
Gyroscope unity remote 3.5 ios 0 Answers
gyro.attitude lags on Samsung Galaxy S2 0 Answers
Sensor Fusion of Accelerometer and Gyroscope 0 Answers
Virtual Reality - Android Gyroscopic Camera - Pitch and Roll Issues. 1 Answer