3D Racing Game Question

Advanced game related topics
User avatar
J. Baker
Addict
Addict
Posts: 2181
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

3D Racing Game Question

Post 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.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
User avatar
TomS
Enthusiast
Enthusiast
Posts: 342
Joined: Sun Mar 18, 2007 2:26 pm
Location: Munich, Germany

Re: 3D Racing Game Question

Post 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.
GBeebe
Enthusiast
Enthusiast
Posts: 263
Joined: Sat Oct 09, 2004 6:52 pm
Location: Franklin, PA - USA
Contact:

Re: 3D Racing Game Question

Post 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".
marc_256
Addict
Addict
Posts: 835
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: 3D Racing Game Question

Post 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
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: 3D Racing Game Question

Post 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.
User avatar
A.D.
User
User
Posts: 98
Joined: Tue Oct 06, 2009 9:11 pm

Re: 3D Racing Game Question

Post 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.
Repeat
PureBasic
ForEver
User avatar
J. Baker
Addict
Addict
Posts: 2181
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: 3D Racing Game Question

Post 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!
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: 3D Racing Game Question

Post 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

Image
GBeebe
Enthusiast
Enthusiast
Posts: 263
Joined: Sat Oct 09, 2004 6:52 pm
Location: Franklin, PA - USA
Contact:

Re: 3D Racing Game Question

Post 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?
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Re: 3D Racing Game Question

Post 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!
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: 3D Racing Game Question

Post 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.
bye,
Daniel
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Re: 3D Racing Game Question

Post 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
User avatar
J. Baker
Addict
Addict
Posts: 2181
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: 3D Racing Game Question

Post 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! ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
Post Reply