I am making a school project, where I controll an sphere with devices accelerometer. Now everithing goes well, till I add rigidbody to the sphere.
Sphere dose move according to the information from accelerometer for few moments, but then it starts to get stuck. Like it would get stuck in the ground(cube in my case).
I am using this code for accelerometer:
//move object using accelerometer
var speed = 10.0;
function Update () {
var dir : Vector3 = Vector3.zero;
dir.x = -Input.acceleration.y;
dir.z = Input.acceleration.x;
if(dir.sqrMagnitude > 1)
dir.Normalize();
dir *= Time.deltaTime;
transform.Translate(dir * speed);
}
How can I get this to work. Or is there a different way to apply movement to the object with information from accelerometer and have gravity.
I am developing with JavaScript for Android 2.2