Page 1 of 1
3D Racing Game Question
Posted: Sat Dec 04, 2010 5:58 am
by J. Baker
I was thinking about making a 3D racing game. But my only concern is how I will make the ai racers follow the road? Or how do I go about creating point destinations on a 3D terrain? Maybe there's a better way that I have not thought of? Any ideas or tips would be great.
Re: 3D Racing Game Question
Posted: Sat Dec 04, 2010 6:24 am
by TomS
Set way points along the road and connect them with spline/bezier curves or simple direct lines (you may need many waypoints for straight lines to look good).
Or you could create the road on a fine mesh and apply the a-star path finding algo. That way bots can drive out of cornets in which they got pushed by themself.
I wouldn't worry about any 3D-stuff except in the displaying section of your code.
Just assume the terrain is flat and your cars are flat. Only 2D collision is needed (exceptions to me made at tunnel crossings and jumps)
Then you just display the Mesh at z = TerrainHeight - CarHeight and rotate it by the angle of the road inclination.
Re: 3D Racing Game Question
Posted: Sun Dec 05, 2010 4:16 am
by GBeebe
What I did in a 2d racing game: I had "way points" that were elements in a linked list, the way point was a structure that had a "close enough" value, and a list of 4 possible next points. A car would head to the selected way point, when the distance between the car and the point was less than the close enough value (otherwise they would sometimes go in circles trying to hit the point), it would randomly select a valid point in the list of next points belonging to the current point. That way the cars didn't drive "single file".
Re: 3D Racing Game Question
Posted: Sun Dec 05, 2010 10:20 am
by marc_256
Hi J.Baker,
I would use NO bezier but only ref points,
NEEDED DATA:
predefined points:
NEW REF. POINTS:
ROAD_left_new_ref (X_left_new, Y_left_new, Z_left_new)
ROAD_right_new_ref(X_right_new, Y_right_new, Z_right_new)
OLD REF. POINTS:
ROAD_left_old_ref (X_left_old, Y_left_old, Z_left_old)
ROAD_right_old_ref(X_right_old, Y_right_old, Z_right_old)
to precalculate:
CAR_old (X_old, Y_old, Z_old) = OLD (previous) center point of the road
CAR_new (X_new, Y_new, Z_new) = NEW (next) center point of the road
And so you can also calculate the CAR rotation
CAR_pitch
CAR_yaw
CAR_roll
If you like to use detection of other CARS,
U must use LEFT limit and RIGHT limit of the road to pass the cars.
GOOD luck, this seems not a simple software.
Greetings,
Marc
Re: 3D Racing Game Question
Posted: Sun Dec 05, 2010 3:12 pm
by Mistrel
If you're open to PureGDK, a lot of the complex stuff for games is built in, like terrain and collision:
http://forum.thegamecreators.com/?m=for ... 77817&b=38
It's a port of the DarkBasic Professional engine and is compatible with any of its native plugins, free and commercial. There's literally thousands of useful code snippets on the DBP forum that can help you get on your feet quickly.
There's also example code included with the DarkPhysics library for vehicle collision and physics so you won't have to calculate it on your own.
Re: 3D Racing Game Question
Posted: Mon Dec 06, 2010 8:52 pm
by A.D.
Another idea would be a recorder which saves your player's input. Then you simply playback your recorded drive for the a.i.
Re: 3D Racing Game Question
Posted: Mon Dec 06, 2010 9:06 pm
by J. Baker
A.D. wrote:Another idea would be a recorder which saves your player's input. Then you simply playback your recorded drive for the a.i.
Interesting idea! Could even move the player slowly and push a keyboard key when you want a point to be recorded. Thanks!
Re: 3D Racing Game Question
Posted: Mon Dec 06, 2010 10:56 pm
by Mistrel
I thought you were initially asking how the AI will adhere to the road through gravity or physics. To get the AI to follow the road itself, what you need is A* pathfinding.
There is a tutorial here:
http://www.policyalmanac.org/games/aStarTutorial.htm
Sample code from TGC forum (there are a lot of them here):
http://forum.thegamecreators.com/?m=for ... =11137&b=6
http://forum.thegamecreators.com/?m=for ... =10057&b=6
PureGDK is also compatible with DarkAI which would give you everything you need:
http://www.thegamecreators.com/?m=view_product&id=2024

Re: 3D Racing Game Question
Posted: Wed Mar 16, 2011 4:44 am
by GBeebe
I like A* path finding, with quad trees, but in a racing game, your cars are trying to get from point A to point A again. How would you force A* to do laps?
Re: 3D Racing Game Question
Posted: Wed Mar 16, 2011 4:47 am
by Rook Zimbabwe
GBeebe wrote:I like A* path finding, with quad trees, but in a racing game, your cars are trying to get from point A to point A again. How would you force A* to do laps?
You have multiple points... i suggest a minimum of 12 for an oval track and
more for more curves!
Re: 3D Racing Game Question
Posted: Wed Mar 16, 2011 7:08 am
by DarkDragon
GBeebe wrote:I like A* path finding, with quad trees, but in a racing game, your cars are trying to get from point A to point A again. How would you force A* to do laps?
You'll just build a invisible wall for the pathfinding at the start line, set the startpoint a bit after it and the end point a bit before it and connect them when A* found a solution.
Re: 3D Racing Game Question
Posted: Sat Dec 24, 2011 5:14 am
by Guimauve
J. Baker wrote:I was thinking about making a 3D racing game. But my only concern is how I will make the ai racers follow the road? Or how do I go about creating point destinations on a 3D terrain? Maybe there's a better way that I have not thought of? Any ideas or tips would be great.
A little hint
http://www.purebasic.fr/english/viewtop ... 16&t=47387
Best regards.
Guimauve
Re: 3D Racing Game Question
Posted: Sat Dec 24, 2011 5:53 am
by J. Baker
Guimauve wrote:J. Baker wrote:I was thinking about making a 3D racing game. But my only concern is how I will make the ai racers follow the road? Or how do I go about creating point destinations on a 3D terrain? Maybe there's a better way that I have not thought of? Any ideas or tips would be great.
A little hint
http://www.purebasic.fr/english/viewtop ... 16&t=47387
Best regards.
Guimauve
Thanks!
