3
\$\begingroup\$

I am finishing a very basic 2D racing game with top-down perspective. I can't get the appropriate formulas to make the movement of the cars fun and addictive... Do you have tips on how to achieve that arcade feeling a lot of games have? Do you know of any guide/tutorial on this topic?

Right now, these are the formulas I am using:

// (speed changes linearly according to the user input)
direction += turnAmount.Value;
Vector3 pos = Position + new Vector3(speed.Value * (float)Math.Cos(direction), 0, -speed.Value * (float)Math.Sin(direction));

I have tested other, more complex options but this is the best I have got so far...

\$\endgroup\$
2
  • \$\begingroup\$ how are you moving cars so far if they are physically simulated? \$\endgroup\$
    – Ali1S232
    Oct 9, 2011 at 20:43
  • \$\begingroup\$ I edited my question to answer yours. \$\endgroup\$ Oct 9, 2011 at 20:54

3 Answers 3

3
\$\begingroup\$

I can you change speed in some non-linear algorithm like :

if(userinput == move_faster)
    if(maxSpeed/2 - oldSpeed/2 <= maximum_acceleration)
        newspeed = (oldspeed + maxSpeed) / 2;
    else
        newspeed = oldSpeed + maximum_acceleration;
else
    if (userinput == stop_move)
        newspeed = oldspeed - someValue;
    else
        newspeed = oldspeed * 0.99;

in this code maxSpeed is the maximum speed that a car can go and someValue is how fast a car stops.

I'm not sure but I guess also you can also change rotation algorithm something like this:

if (newspeed > somevalue2)
    direction += turnAmount.value / newspeed * somevalue2;
else
    direction += turnAmount.value * newspeed / somevalue2;

in this code somevalue2 represents a speed value in which your car is moving by a reasonable slow speed, let's say if you car can move by max 10m/s setting somevalue2 as 1 seems to be a good choice (although you have to test it runtime).

\$\endgroup\$
2
  • \$\begingroup\$ giving formula you describe, when player will press acceleration button for first time, initial speed will be directly half max speed. this is a little brutal, no ? \$\endgroup\$
    – tigrou
    Mar 10, 2012 at 10:07
  • \$\begingroup\$ you can always create a maximum value for changes. I've edited my answer to prevent that situation. \$\endgroup\$
    – Ali1S232
    Mar 10, 2012 at 10:17
2
\$\begingroup\$

To get realistic looking movement, you have to apply as realistic physics as you can.

That would involve giving the cars momentum, velocity & mass and interact forces/torques (turning, acceleration, etc.) upon those momentum vectors in the same way an actual automotive engineer might.

Here's a good resource to introduce physics into your game. It's 3d but the principles can easily be applied to 2d as well.

http://gafferongames.com/game-physics/physics-in-3d/

\$\endgroup\$
4
  • 3
    \$\begingroup\$ Realistic is not the same as "fun." I think the question here is about fun, not realism. \$\endgroup\$
    – ashes999
    Oct 10, 2011 at 2:59
  • \$\begingroup\$ Yes, I am trying to give the game a fun, arcade feeling... I think that making it realistic would be easier! \$\endgroup\$ Oct 10, 2011 at 10:01
  • 1
    \$\begingroup\$ @ashes999 Even though you're right that realism != fun, basing the physics on reality isn't a bad idea. The movement 'feels' natural, but you can tweak the variables in your calculations to add an arcade-y feel to it. \$\endgroup\$ Mar 10, 2012 at 22:40
  • \$\begingroup\$ @ErikvanBrakel I agree with you 100%. That's a great approach. \$\endgroup\$
    – ashes999
    Mar 11, 2012 at 1:17
0
\$\begingroup\$

Understanding the separation between realistic physics and fun physics, I suspect real physics are still a really good stepping point as a starting point, and then hacking around the physics to make it fun.

There is a fairly comprehensive guide to racing physics on http://phors.locost7.info/contents.htm. To be fair, I have only read small amounts of it and can not attest to its quality.

I would then start working on special cases - so, for instance adjusting friction when braking to make it more playable, and 'nudging' the car towards driving straight in the correct direction after drifting.

\$\endgroup\$

You must log in to answer this question.

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