- Home /
tilt control acceleration
Hey guys,
I'm trying to build in a tilt control game for the iPhone. The phone is held vertically and the object is controlled with tilting left and right.
For that I used this script:
// Move object using accelerometer var speed = 125
function Update () {
var dir : Vector3 = Vector3.zero;
// we assume that device is held parallel to the ground // and Home button is in the right hand
// remap device acceleration axis to game coordinates: // 1) XY plane of the device is mapped onto XZ plane // 2) rotated 90 degrees around Y axis
// dir.x = -Input.acceleration.y; dir.z = Input.acceleration.x; // Z is the axis which controls left and right.
// clamp acceleration vector to unit sphere if (dir.sqrMagnitude > 1) dir.Normalize();
// Make it move 10 meters per second instead of 10 meters per frame... dir *= Time.deltaTime;
// Move object transform.Translate (dir * speed); }
And it works really good actually. My only problem with this is that the control is very linear. Doodle Jump for example, accelerates in a different way. if you tilt it very soft, the character moves slow, if you tilt it hard the character moves fast.
But in this script, the speed of the movement does nothing, the acceleration is always the same.
I would really appreciate any tips on that matter.
i try so hard to translate this in my script. i don t know why people don t post it normal to understand everyone.
Answer by Minthos · Feb 24, 2011 at 04:41 PM
// clamp acceleration vector to unit sphere
if (dir.sqrMagnitude > 1)
dir.Normalize();
Perhaps this is the problem? If dir typically has magnitude greater than one, this ensures you typically get constant acceleration.
Your answer
Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
iPhone Gyroscope problem 0 Answers
iPhone swipe to look 0 Answers
iOS Tilt input and constant force 0 Answers
How to set up virtual D-Pad for iOS? 1 Answer