Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Racing Game AI

Author
Message
Fighter Bluestorm
19
Years of Service
User Offline
Joined: 2nd Aug 2005
Location:
Posted: 16th Jan 2007 03:33
I'm on the A.I. part of my racing game so I was planning to use the Limit Rush system which we all know is the objects being attracted to other objects etc... But I started thinking the place may be an issue with that system (1st, 2nd, 3rd, etc.) Anyone have any idea's with that one?

Also I heard there may be another system to use involving paths or something...

I appreciate any help! Thanks in advanced!

AL: "Big Brother I Have Too Pee!"
ED: "Your A Peice Of Freakin' Armor!"
Choccy monster
18
Years of Service
User Offline
Joined: 25th Nov 2006
Location:
Posted: 16th Jan 2007 12:11
The traditional approach is to use a series of waypoints placed sequentially along your track ( creating a best line to follow )and your ai cars steer towards each one in turn, when the ai cars come within a certain distance to its intended waypoint, it heads for the next one in the sequence, until the last waypoint is reached ( usualy on the start finish line ) when the ai cars start over and head for the first waypoint again.

Each waypoint is usualy just an x,y,z position in 3d space ( assuming your using 3d ) which doesnt have to be a 3d object, just a coordinate or vertex. Also, along with the waypoints x,y,z position, you will want an associated speed, which the ai cars will attempt to reach. This way you can get the cars to slow down for corners and speed up on straits. Also allows for refining dificulty evels.

You will also need some code to determine if your ai car points to the left or right of its intended waypoint. If i remember correctly, i used the DOT Product for this which also gives the angle between your cars yaw orientation and the waypoint. The sign +- of the Dot product i think.


I would also advise that your ai cars steering angle is set to point directly at the waypoint at each pass of your code, assuming the maximum angle isnt reached ( you dont want your ai cars steering angle for instance to go beyond 90 degrees ).
If, for instance your ai cars take a certain amount of time to change the steering angle, ( rate of turn of the steering wheel ) you will find that your ai cars wobble down the track, swaying from side to side. Not cool

In my code, my a cars head for the 3rd waypoint ahead of the closest one to the car and they are spaced quite close together. I may have between 100 - 200 waypoints per track.


You could also investigate the ai car sim RARS which uses a different technique of getting the ai cars to keep a set distance from each edge of the track.

Hope that helps.

A choc a day keeps the doctor away
Fighter Bluestorm
19
Years of Service
User Offline
Joined: 2nd Aug 2005
Location:
Posted: 16th Jan 2007 19:49
Thanks, that was the method I was planning to shoot for but I hear there have been a few problems with it! But you've explained it quite well. But, I'm still curious if there a more accurate system out there instead of the "waypoint" method. I reacall hearing something about hot spots or something, anyone know anything about that?

AL: "Big Brother I Have Too Pee!"
ED: "Your A Peice Of Freakin' Armor!"
Fighter Bluestorm
19
Years of Service
User Offline
Joined: 2nd Aug 2005
Location:
Posted: 17th Jan 2007 01:59
Choccy I was wondering if you could provide so basics I'm attempting to do it alone but I seem to be very much lost. Would you mind?

AL: "Big Brother I Have Too Pee!"
ED: "Your A Peice Of Freakin' Armor!"
Choccy monster
18
Years of Service
User Offline
Joined: 25th Nov 2006
Location:
Posted: 17th Jan 2007 11:39
Hi again.

I'm not sure what the "HOT SPOT" method you refer to actualy is.

I'm assuming you want your ai cars / vehicles to race around a track or at least follow a road / path.

I'm not a user of dark basic any more but a rival product so cant really provide any code examples, sorry.

I've used the waypoint method with great success, giving quite a professional game feel to the ai cars. I can adjust the difficulty levels so they are far greater than me, and i've been playing racing games for many years now. My ai cars can easily outperform me.

I would advise trying the waypoint method first to see what sort of results you get.

My ai cars actually head in the general directon of the waypoint, +- 10 - 15 degrees to the left or right of the waypoint. This allows the cars to drift down the track and to not strictly stick to the ideal line which the waypoints mark out.

This allows the cars to duck and dive for position with each other, and i also give each of the ai cars slghtly different handling and acceleration characteristics. This allows the cars to overtake each other, push each other off the road ect.

A slightly more advanced technique is to use splines or curves to define your best line. These again are waypoints / vertices wich define a curve based on much fewer waypoints or 3d points. This will give you a much smoother line for your ai cars to follow but is a bit harder to code. I would advise the waypoint method first and then move on to splines if you require more accuracy.

But in my experience, splines don't really give you that much of a benefit over waypoints. Maybe smoother movement thats all. The coding is trickier as you have to seek down the spline to find the point your heading for and also need to work out the speed at that spline point too.

An even more advanced approach is to use re enforced learning.
This is basically a way to teach your cars how to drive. By repeatedly driving around the track, saving the lap time, then making a small random adjustment to the ai / physics, then do another lap and see whether that lap time was quicker than the last. If it is, you keep that new change and make another random one .

This way, the car teaches itself how to drive.

Think of a rat in a maze. He randomly searches each corrider learning and remembering dead ends as he goes until he finds the exit. Finding the best path.


This is much more advanced vehicle ai and to be honest isn't necesary at all for game racing ai. But i'm sure if you search the net you'll find lots of tutorials on path finding, vehicle ai ect. There are plenty of AI specific websites out there.

If your racing on a track, then you generally want to follow the fastest / best line.

You could also check out geoff crammonds f1gp games, which use a CCLINE approach. There is some info out there on the net about it, and might lead you on to other areas. This again is a best line to follow approach.

Hope that helps.



A choc a day keeps the doctor away
Fighter Bluestorm
19
Years of Service
User Offline
Joined: 2nd Aug 2005
Location:
Posted: 17th Jan 2007 20:55
Wow, your fantastic when it comes to describing methods! You out to be a teacher or something! Your info really has helped out alot as soon as my game is finished, I'd be honored if you'd be one of the first to play it!

AL: "Big Brother I Have Too Pee!"
ED: "Your A Peice Of Freakin' Armor!"
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 17th Jan 2007 22:20
Quote: "I'm not sure what the "HOT SPOT" method you refer to actualy is."


If I'm not mistaken, he could be referring to hotspots in MatEdit which actually were no more than waypoints under a different name.

They wouldn't have been of any use for a racing game though because you could only assign ten of them...

TDK_Man

Choccy monster
18
Years of Service
User Offline
Joined: 25th Nov 2006
Location:
Posted: 18th Jan 2007 12:07
Glad to be of help.

Would love to playtest your game.

And, thanks to TDK for the hotspots info.

I used matedit many years ago for dbc. A good utility

A choc a day keeps the doctor away
Fighter Bluestorm
19
Years of Service
User Offline
Joined: 2nd Aug 2005
Location:
Posted: 18th Jan 2007 17:32
Quote: "If I'm not mistaken, he could be referring to hotspots in MatEdit which actually were no more than waypoints under a different name.

They wouldn't have been of any use for a racing game though because you could only assign ten of them..."


I should of actually mentioned that sooner, for those who have played "Limit Rush", where the glowing lights become the target, this is the system it uses and TKD_Man is right 10 hotspots is simply not enough, especially since Choccy described that he used 100-200 waypoints. The "hotspot" system may be useful for small racing projects but even then the tracks wouldn't be very creative. (P.S. TKD_Man I'm the moron know as [email protected] that e-mailed you trying to figure out matedit, LOL.)

Quote: "Would love to playtest your game."

As soon as I finish. (Very lazy person with website/sprite comics/webcomic projects.)

AL: "Big Brother I Have Too Pee!"
ED: "Your A Peice Of Freakin' Armor!"
Fighter Bluestorm
19
Years of Service
User Offline
Joined: 2nd Aug 2005
Location:
Posted: 19th Jan 2007 21:42
Okay I think I have the waypoint method down, I'm just doing a bit of fine tuning. But being the kind of person that I am! My mind has already begun to wonder about another problem, and that is placing.(1st place, 2nd place, etc.) Any ideas on this one?

(You don't have to help w/ this one Choccy, I've bugged you enough. Same for you TKD.)

AL: "Big Brother I Have Too Pee!"
ED: "Your A Peice Of Freakin' Armor!"
Roxas
19
Years of Service
User Offline
Joined: 11th Nov 2005
Location: http://forum.thegamecreators.com
Posted: 19th Jan 2007 21:49
Drive yourself like 10-20 times and store drives in arrays then give your random drive array a.i to opponet

I have no soul.. I nobody.. I have no heart.. I have felt in the darkness.. Im the darkness.. Whatever..
Choccy monster
18
Years of Service
User Offline
Joined: 25th Nov 2006
Location:
Posted: 20th Jan 2007 11:51
Glad you got the waypoint system working, didn't take you long

Yeh, calculating position took me a while to figure out.

The method i used again involves distance checks to waypoints along with sorting.

First all cars are sorted by the current lap theyre on. With those cars with the highest lapcounts being top of the list.
A car on lap 10 for instance obviously goes above a car on lap 7 in the sort list.

Then all cars which are on the same lap need to be sorted as to whos in front and in what order on that lap.

This was done again by simply sorting the cars based on what waypoints theyre heading for. Those cars heading for waypoints further down the track are obviously ahead of those which are heading for waypoints further back down the track.

Then you need to sort any cars which are on the same lap and heading for the same waypoint.

This again is simply a distance check to that waypoint for each car thats headed for the same waypoint. The cars are sorted based on how close they are to the waypoint, those that are closer being higher up in the list.

All these checks are necesary in order to build up a sorted list of car placements. The car top of the list will be in first place, the car bottom of the list obviously last place.




@The Full Metal Coder

Yeh thats a good way to generate the speed data for the waypoints, which would basically level the dificulty of the ai to your ability.

Something which i do as an initial state then refine the speed data later for fine tuning.

A choc a day keeps the doctor away
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 21st Jan 2007 22:58
Choccy monster:

So in simple terms, you could give each car a 'positional score'?

Eg (with 200 waypoints per lap):

CarPosition = (CurrentLap*200) + LastWayPoint + DistFromLastWaypoint

Then, each car would have a score (CarPosition) which is used to position them on a leader table.

TDK_Man

Choccy monster
18
Years of Service
User Offline
Joined: 25th Nov 2006
Location:
Posted: 22nd Jan 2007 13:51 Edited at: 23rd Jan 2007 11:59
@TDK

Yes, but i would make a small ammendment there, because your introducing the waypoint distance into the equation, that becomes the lowest common denominator, so the overall score should be expressed in terms of overall distance travelled.

CarPosition = ((CurrentLap * 200) * waypoint_distance) + ((current_waypoint -1) * waypoint_distance) + distance_to_last_waypoint

This assumes all waypoints are equally spaced, otherwise you would have to calculate the distances between each waypoint to get an accurate overall score.

Also the -1 is to the last waypoint travelled too on this current lap, and then add in the distance to the last waypoint as you should be ahead of it.

This also assumes current_waypoint > 1

then as you say, sort the list into highest score first, descending to last position.

I personaly don't do it that way, but i see no reason why not. Makes alot of sense to express positions in terms of overall distance travelled.

Let me know if you see any flaws in my modification.



* edited as i saw a few flaws. *

A choc a day keeps the doctor away

Login to post a reply

Server time is: 2025-05-26 03:20:53
Your offset time is: 2025-05-26 03:20:53