- Home /
how to limit the rotation of an object by tilting the device?
I'm doing with the plan accompanying the slope of a device, it happens that when I lean up to 90 degrees the plan continues to lean against a rotation up to 360 degrees. How to limit?
see how is my script.
using UnityEngine;
using System.Collections;
public class SceneScripts : MonoBehaviour {
public Vector3 rotateDir = Vector3.zero;
public float rotateSpeed = 3.0F;
// Update is called once per frame
void Update() {
rotateDir.x = -Input.acceleration.y;
rotateDir.z = -Input.acceleration.x;
if (rotateDir.sqrMagnitude > 0.2)
rotateDir.Normalize();
transform.Rotate(rotateDir * rotateSpeed);
}
}
Comment
Your answer

Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Motorcycle/Bike Physics Trouble 5 Answers
iOS Tilt input and constant force 0 Answers
Making script only effect one gameobject when attached to multiple 2 Answers
How to tilt my bus when it turns? 3 Answers