So I have a simple 1D "racing" game, with a single button the player can press to max the gas pedal and there is also some other stuff going on.

I think acceleration should be highest somewhere at medium velocity (or medium RPM for each gear), and taper off towards maximum velocity, no? What is a good set of functions to model this?

Do I need to model RPM too? I'm not sure whether to model different gears too, but I thought they'd each follow more or less the same function.


1 Answer 1


I can't imagine a single dimension racing game could be very interesting. Anyway, I don't know anything about cars but you can make it as complicated as you'd like.

Basically you need a function that reaches a peak since cars will not indefinitely accelerate.

Some examples would be

sin(x), x = 0 to pi

ax^2 + bx = 0 for a < 0 and b > 0

x * e^(-(x - n)), x = 0 to n

Bessel Function of the first kind for n = 1 and x = 0 to ~3.85

You can be as complicated as you'd like with the function. Then to find the velocity and position at any given point take the anti-derivative with respect to time, once to find the velocity, and again to find the position. You don't necessarily need to do that last part you can model it anyway you like through trial and error which will likely need to happen anyway. If you'd like to go this route I'd suggest picking an easy function like the quadratic equation, the second example, as it's easy to work with and you'll find enough information on the interwebs to get a generic answer for both without having to do the calculus if you've not taken an introductory course in it.

Edit: I've thought about this a bit more and I think the easiest thing to do would be to use some type of piecewise function. This will give you a bit more control as to what's going on.

For example, x*e^(x), x <= max acceleration then when x = max acceleration x, x = max to 0.

Since this will update rather frequently, however you have that set up, then the result can just be added constantly to a velocity variable and the position updated accordingly. No need for calculus. And again this will give you a lot more control as you can more easily decide how quickly to accelerate and how quickly it will stop accelerating.

  • \$\begingroup\$ Thanks for the vote of confidence ;) Which of those functions is most realistic with respect to real cars? 1, 2 and 4 all have a very steep decline, is that what actually happens? (Not to say that I am looking for realism per-se, just curious) \$\endgroup\$
    – noio
    Commented Jan 28, 2013 at 15:59
  • \$\begingroup\$ Every car has a different acceleration curve (among other things, like how the suspension behaves), so if this is a fictional car you can feel free to play around with it to find what "feels best." Otherwise, check with some of the car forums and see if you can get them to send you of some of their graphs. \$\endgroup\$
    – jzx
    Commented Jan 28, 2013 at 16:50
  • \$\begingroup\$ I was just poking fun at your use of 1D, I imagine the constraint would make it rather difficult to pass someone in front of you! Also, it probably depends on the car and the conditions. I'm assuming you'll likely model this with 0 drag and 0 friction, which would change the functions quite a bit. \$\endgroup\$
    – Tony
    Commented Jan 28, 2013 at 16:52

You must log in to answer this question.

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