- Home /
How rotate the cam by acceleration
Hallo, i am new with Unity3d. I want create an Iphone app. I have i scene with a car and in the middle of the car is a cam. I want to rotate the cam at 360 degrees, so that i can see the hole inside of the car. I tried it by using acceleration, but the problem is the rotation don't stop. I want to rotate the camera in the scene in the direction in which I hold the iphone. I don't want a permanent rotation. The code the i tried is the follow:
// Move object using accelerometer var speed = 10.0;
function Update () { var dir : Vector3 = Vector3.zero;
// we assume that device is held parallel to the ground
dir.y = -Input.acceleration.y;
dir.x = Input.acceleration.x;
// clamp acceleration vector to unit sphere
if (dir.sqrMagnitude > 1)
dir.Normalize();
// Make it move 10 meters per second instead of 10 meters per frame...
dir *= Time.deltaTime;
// Move object
transform.Rotate(dir * speed);
}
I think it must stop after the first rotation. i hope someone can help me.
Your answer
Follow this Question
Related Questions
Input Text Rotated incorrectly... is this a BUG? 1 Answer
Zero-ing the Input.acceleration.z 0 Answers
Rigidbody Turning 2 Answers
Rotating doesn't work correctly? 2 Answers
Character Controller for a vehicle? 2 Answers