Subscribe to:

The Kiwi's TaleWitchBlasterDerelict Blow Stuff Up

Simplified acceleration in games

In some genres of games (Such as FPS, Platformer etc) the player's character usually has an acceleration to it's movements. I assume that for the vast majority of games this acceleration is arbitrary, and not actually based on real world physics as this would be cumbersome and artificial.

Somewhere I stumbled upon a Blitz3D sample that I believe might be the best example of a simplified acceleration formula. In pseudo-code it might be rendered as:
 
Speed += ((MoveDirection * MaximumSpeed) - Speed) * AccelerationFactor
 
Where:
  • Speed is the current speed the entity is travelling at on the current axis.
  • MoveDirection is the direction the entity is trying to travel in on the current axis, 1 is forward, 0 is still and -1 is backwards. All values in between are allowed.
  • MaximumSpeed is a constant determining the fastest that the entity can travel on the current axis.
  • AccelerationFactor is a constant between 0 and 1 that represents the rate of acceleration and deceleration. 1 is instant, and 0 will never move.
The beauty of it is that it works equally well for travelling forwards and backwards, and acceleration is curved rather than linear. That said, it's still not perfect, for instance you can't define a specific acceleration rate.
 
Any suggestions for improvement would be gratefully appreciated.
Tags:

Comments

Joshua Smyth (not verified)

In C# the mathematical operators are overloaded. So Speed and MoveDirection can be 2D vectors and the other variables can be floats or doubles. Which is closer to the notation used in math.

That said, if I'm reading the formula right maximum acceleration occurs from speed = 0 and the rate then slows down as it's speed increases. This seems right for something like a rocket thrust, but I'm not so sure if it's right for something like a car.

PS I know very little about physics.

 

Joshua Smyth (not verified)

Actually now that I think about it (It's early and I've only had one coffee) - That formula does seem to make sense.

I do wonder if it's worth implementing more of an S shaped curve. Slow inital to maxium acceleration to slowed acceleration as you reach the maximum.

I should probably read more about physics for games at some stage (or at least program a platformer.)

The most important part is how it feels in gameplay :)

Earok
Earok's picture
Offline
Joined: 02/06/2009

Never thought about doing it with vectors!

You did read it right - Quick initial acceleration, but slows down towards top speed (Which it never will reach unless you round upwards).

I think having an initial burst of speed is best as it allows players to quickly get out of the way of incoming projectiles, however you still need a long run-up if you want to jump over a wide ledge.

From my experience it 'feels' right in First Person Shooters, though I've yet to test it out in a Platformer. I was never 100% happy with the movement of the Kiwi in The Kiwi's Tale, which had no acceleration while walking but a little while jumping (Left-right movement, up-and-down movement still follows a relatively realistic gravitational drop). I think I'd have the same acceleration formula for both situations, but lower the acceleration factor for moving while jumping.

Earok
Earok's picture
Offline
Joined: 02/06/2009

Also, the quick acceleration works backwards too. You get a rapid dropoff from maximum speed when not moving - handy if you change your mind about jumping a ledge!

Joshua Smyth (not verified)

I remember in Starcars the deceleration factor was about 8x the acceleration factor - people kept falling off those damn ledges.

Earok
Earok's picture
Offline
Joined: 02/06/2009

Haha, isn't insane difficulty the point of a Skyroads clone? ;)

Speaking of which, have you considered bringing the game to XNA and trying to get it into XBLA?

Anonymous (not verified)
hello I want someone to teach BASIC programming language with Blitz3D because I have said that in the right hands is a potential weapon
Anonymous (not verified)

please if someone replies to hang it on wall facebook Tomy Bryan Lindo Huayhua 

hahaha. that's my real name

I speak Spanish but I am using the translator

sorry if I write something wrong 
 
Andrei Bodnarescu (not verified)

This is one of the most useful game dev advices I've ever found. Thanks