- Home /
limit accelerometer controlled rotation
I have an object that is rotated on its y axis using the accelerometer. The problem is: i want the y rotation value of this object to stay between -5 and 5. The starting rotation value on the y axis of this object is 0. I tried lots of solutions, using Mathf.Clamp but nothing worked. Can someone suggest me something? I read that the solution could be to store the rotation value in a variable and then limit it using mathf.clamp, something like:
var yangles : float = 0.0;
function Update () {
yangles = Input.acceleration.y;
yangles = Mathf.Clamp(yangles, -5,5);
transform.rotation = Vector3(0,yangles,0);
}
This didn't work either.
Answer by Martians135 · Jun 16, 2017 at 05:14 AM
May be this asset can helps: You can use this asset to Do the rotation. you can use the accelerometer like a gyroscope , this works on all phones, because all devices have accelerometer. And works on all axes. Here this asset: https://www.assetstore.unity3d.com/#!/content/87609
Your answer
Follow this Question
Related Questions
How to limit the rotation of an object?? 2 Answers
accelerometer Rotation limiting 1 Answer
c# problem with limiting rotation (with rigidbody) 1 Answer
Lock rotation (range of motion) of auto-aiming bullet spawner 2 Answers
Clamp Rotation Problem 1 Answer