Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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...

share|improve this question
    
how are you moving cars so far if they are physically simulated? –  Ali.S Oct 9 '11 at 20:43
    
I edited my question to answer yours. –  miguelSantirso Oct 9 '11 at 20:54

3 Answers 3

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).

share|improve this answer
    
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 ? –  tigrou Mar 10 '12 at 10:07
    
you can always create a maximum value for changes. I've edited my answer to prevent that situation. –  Ali.S Mar 10 '12 at 10:17

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/

share|improve this answer
3  
Realistic is not the same as "fun." I think the question here is about fun, not realism. –  ashes999 Oct 10 '11 at 2:59
    
Yes, I am trying to give the game a fun, arcade feeling... I think that making it realistic would be easier! –  miguelSantirso Oct 10 '11 at 10:01
    
@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. –  Erik van Brakel Mar 10 '12 at 22:40
    
@ErikvanBrakel I agree with you 100%. That's a great approach. –  ashes999 Mar 11 '12 at 1:17

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.