- Home /
Question by
maninduw · Feb 23, 2014 at 05:35 AM ·
rotationaccelerometer
How to rotate an object using accelerometer under a limitation of the angle ?
Hello, I'm trying to rotate a rigidbody2d around the z axis. I want to limit the rotation to 15 degrees to left and right. This is the code and It doesn't seem to be limiting the roation. Any help would be appreciated.
Thank you.
void Start()
{
initialAngles = transform.eulerAngles;
curAngles = Vector3.zero;
}
void FixedUpdate(){
float dir = 0;
dir = -Input.acceleration.x;
if (Mathf.Abs (dir) > 0.2) {
curAngles.z += rotSpeed * Time.deltaTime * dir;
}
curAngles.x = Mathf.Clamp(curAngles.x, -15, 15);
transform.eulerAngles = initialAngles + curAngles;
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613134427im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Using Accelerometer to move and rotate a 3d cube from left to right 0 Answers
Flip over an object (smooth transition) 3 Answers
How to rotate an object to face the direction of the accelerometer in 2D 2 Answers
I want to rotate an object by the Y axis using the phones accelerometer 0 Answers
Smooth Accelerometer tilt rotation 0 Answers