I’m trying to make a character rotate around it’s own Y-axis when the iPad is tipping left or right, and move forward (or backward) along it’s Z-axis when the device is tipping forward and backward. This is close, but not exact … how do I add the Z-axis movement? (My commented out stuff doesn’t work, btw.)
var speed = 5.0;
private var myTransform : Transform;
function Start() {
// Cache "hidden" GetComponent calls for extra speed
myTransform = transform;
}
function Update () {
// assume that device is held parallel to the ground and Home button is in the right hand
var dir : Vector3 = Vector3.zero;
dir.x = -iPhoneInput.acceleration.y; // left and right
dir.z = iPhoneInput.acceleration.x; // fwd and bkwd
// clamp acceleration vector to unit sphere
if (dir.sqrMagnitude > 1) // 1
dir.Normalize();
// Make the player move 10m/s instead of 10m/f...
dir *= Time.deltaTime;
// Move and rotate player in direction iPad is tipped in
transform.Translate (dir * speed);
// transform.Rotate(0, (dir.x * 720), 0); --- not working with forward movement but spins around fine (I think?)
// snipped
}