Hey, I’m supernew in Unity… I’m trying to figure how to make a cube move like an ice cube on a tray using the iphone accelerometer. So the trick is that if I increase the angle of inclination the cube has to accelerate incrementally and decelerates if I tilted the device to the opposite side. So far I’m playing with this code from the reference without any luck:
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);
}
Can someone help me figure it out?
Thanks!