I was wondering how collisions in some simple 3d car racing games are done (especially in games like Outrun 2/Motoracer).
In classic car racing games with complex environment (open world), I guess this is done with a basic box (for the car) to plane collision (for track, buildings an other stuff). The whole thing would be optimized using some bounding boxes (this is the way collision is done in many games).
In a game like Outrun 2/Motoracer, the gameplay is so simple that developers maybe dont need that and everything could have been simplified a lot. For those who never play it, here is what is so specific :
- The car/bike is always glued on the road.
- The road is always same size and have a very simple shape.
- The only possibilities is to follow that road, its not possible to leave the road, or to get in collision with something else (except other cars/bikes but we don't care).
- When you collide with the road, very basic arcade collision is done (the car is simply pushed away from it)
Here is how i think collision (could) have been done :
The whole track could be considered as giant a 3d bezier curve. From that curve, the road polygons could be generated (using front, left and up vectors generated from curve). Other elements (like houses, trees, ...) could be also placed and aligned using this method.
Then, to handle the collisions (and draw car) :
1) Find closest position on 3d curve from current car 3d position. In other words, transform 3d car position to bezier curve position. Every 3d position on the road could be considered as a displacement along 3d curve (
t) + lateral displacement (
d). Check image below if it is not clear (this is a 2d example but this apply to 3d easily).
when t = 0 car is at beginning of track section, when t = 1 car is at the end. when d = -1 or 1 car is at border of track, when d = 0 car is in the middle of the road
2) align the car to the road using
d (very simple : for any
d values i can get a 3d position + up/front/left vectors). the car is now glued on the road
3) check lateral displacement
d of car. if value is too big
(d > 1) or to low
(d < -1) car is away of track. just clip it to put car in correct place.
This also make 3d culling very simple, just draw the track from current car
t position to
t + some_big_enough_value_to_avoid_visible_clipping.
Or maybe i'm completly wrong : it would have been lot faster and simpler to just check collision of the car (a bounding box) and a very simplified set of polygons that represent the track (without the buildings and such). The 3d world (and the resulting colision model) would have simply been generated before, using some 3rd party tool (no more 3d curve when running the game, just a bunch of polygons).