I'm developing a game for iPhones, which have a body placed in the bottom center of the sreen, and I want to move that body in horizontal axis by player tilting his device in y axis.

Everything okay with that, but I want the body to move in a physical-credible manner.

I have a formula for a velocity of the body:

V[current] = V[previous_step] + acceleration * dt;

I don't understand (totally) a couple of things:

  1. If user tilt a device, and we have a float value aTiltVector, that changes through -1 to 1, and gives us a magnitude and direction of a tilt, should I add this vector at beginning as an acceleration, or startup velocity? Should I add this value to the velocity of the body or its acceleration?
  2. How should my body stop? If we give an initial velocity and acceleration, how should it stop if no other force is impacting our body? It would roll down to the edge of the screen then.
  3. How do you typically achieve that behavior?

1 Answer 1


When you want it to be physically credible, all of your objects will accelerate slowly and not instantly. So add/subtract an amount of speed from the current speed of your object which is proportional to the current tilt factor.

To prevent your object from accelerating and moving indefinitely, there is friction. Friction increases quadratically with speed. So every physics frame you reduce the speed by

speed -= (speed * speed) * friction

The ideal friction should be a floating point number somewhere between 1.0 and 0.0 (but usually closer to 0.0). The exact number depends on how high your speed is and how easy you want your object to control. The ideal value needs to be found through experimentation. A higher value means a lower top-speed which is reached quicker but also makes objects stop earlier.

  • \$\begingroup\$ Wait friction is quadratic? I always assumed it was linear. (e.g. speed -= speed * fricion) \$\endgroup\$
    – API-Beast
    Commented Oct 10, 2014 at 14:10
  • 1
    \$\begingroup\$ @API-Beast Yes, it is. Imagine you are driving a car through a corn field. When you have twice the speed, you hit twice as many corn knobs per second, and every single impact is twice as powerful. So the force you experience increases quadratic with your speed. \$\endgroup\$
    – Philipp
    Commented Oct 10, 2014 at 15:23
  • \$\begingroup\$ So I should change acceleration but I should change speed, is that right? \$\endgroup\$
    – PaulD
    Commented Oct 13, 2014 at 11:11
  • \$\begingroup\$ Could you please take a look at my question here @Philipp, as I'm still struggling with a similar problem....... gamedev.stackexchange.com/questions/109920/… I think the problem is just this - I am accelerating 'instantly' thus it gives the game an odd feel and I can't work out how to do it correctly - thanks \$\endgroup\$ Commented Dec 12, 2015 at 15:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .