- Home /
My object moved even i havent tilt my phone...
My problem now here is when i open it in my phone my object move on its own and i havent tilt my phone.
here is my code..
vard card: GameObject; function Start () {
card = GameObject.Find("GameObject");
}
var speed: float = 10.0f;
function Update(){ var dir : Vector3 = Vector3.zero;
dir.z = -Input.acceleration.z;
if (dir.sqrMagnitude > 10)
dir.Normalize();
dir *= Time.deltaTime;
card.transform.Translate (dir * speed);
card.rigidbody.AddTorque(0, 0, 50);
card.rigidbody.AddForce(transform.forward * 50);
card.rigidbody.useGravity = true;
}
Is the phone down flat on its back?
I think you should display accelerometer x,y,z in OnGUI(). You might be surprised.
vard card
Typo
Get rid of those three lines at the end there. They will move the object no matter what the accelerometer says.
Use the OnGUI(). Here: http://docs.unity3d.com/Documentation/Components/gui-Basics.html