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 Professional Discussion / Race Game Ideas or Suggestions???

Author
Message
ScottyB
18
Years of Service
User Offline
Joined: 26th Jul 2007
Location:
Posted: 29th Sep 2010 14:37
I've recently started a race game.
One car is controlled by user the others by cpu.
They just go around the track at various speeds.
Is there a way to give them more life??? (AI)
There is contol way points that they follow if that
can be a starting point.
There just to stiff if you know what I mean.
They need some versatility can anyone help???
Any thoughts???
nitrohaze
23
Years of Service
User Offline
Joined: 21st Apr 2003
Location:
Posted: 29th Sep 2010 15:21
Build in a random chance of your AI cars making a mistake, spinning, braking early or late etc.
Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 29th Sep 2010 16:41
Yep, that would be cool, i have never ever seen a CPU car - out of any bugs of course - making any mistakes, and that always makes me sad... and angry...
gbark
20
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 29th Sep 2010 18:05
Definitely adding "mistakes" and other variations to the AI's movement will go a long way to making it seem more human.

I highly recommend reading the various articles here, there's a lot of useful information that you can use to add realistic looking behaviors to your AI. In particular, I'd check out the path following article for getting a general movement around the track, and the crowd path following to get some ideas on how you might handle multiple CPU racers running at the same time.
Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 29th Sep 2010 21:01
Perhaps you could add multiple paths to the waypoints?

In general you have a standard circular path around the track, but at various points that path forks off, so that the circular path around the track puts the car in a different "position" within the driving surface itself.

Adding checks to see if it will hit a car before moving onto the alternate path, perhaps adding minor speed bonuses or penalties to different movement paths (i.e when going through a turn the car might prefer and inside path nearest to the inside of the curve, if it can move over without hitting anyone, etc..)

Could have driver personalities, maybe the red car is afraid of the black car and has trouble trying to pass it, or might make a mistake if the black car is behind it and trying to move up, etc.

Scraggle
Moderator
23
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 30th Sep 2010 10:57 Edited at: 30th Sep 2010 11:14
I have been researching racing AI for a university dissertation and there are many things you need to consider when writing AI for a racing game:

Follow the racing line.
Adjust speed to maintain appropriate velocity for the part of track that the vehicle is on.
Avoid collisions with other vehicles.
Move to an overtaking position.
Move to a blocking position to avoid being overtaken.
Try to stay on track.
Drive back onto the track if the above failed.
The AI must be beatable!


... there may be others but if you can get the above list working then you should at least have a reasonable AI.

The first piece of advice I can offer is this: when dealing with racing AI consider the game world to be 2D. It doesn't matter to the AI if you are writing a 2D top down racer or a full 3D in-car racer. The track is essentially 2D. It may have undulations that cause the cars to speed up or slow down but that is unimportant as you will see when you read on.

Follow the racing line: From what you have said, I am guessing that the system you have at the moment is a series of waypoints that the AI cars drive to and then move on to the next. If those waypoints are on the racing line then you have satisfied the first point. But it will be like watching items on a conveyor belt and not very race-like.

Adjust speed to maintain appropriate velocity for the part of track that the vehicle is on: You say you have a player operated car (POC) working at the moment and that is a good start. Is the POC able to lose traction and slide off the road or can it take corners as fast as the player chooses? If you don't have a maximum lateral traction, then I would suggest that is the first step you want to take.

Once you have that working you can adapt your waypoints to include more information. At the very least they should have a maximum speed at that point but don't asssign that maximum speed to each car but consider it a target and choose a random speed that is close to it (more under than over). That way you will have more realistic cornering because each AI will either take the corner slightly slower than maximum or slightly faster - at which point they will lose traction and slide off the road.

Also, don't consider the waypoints as targets that each AI must get to. Instead consider them as a target that they try to get to but getting close is good enough. A simple distance check would do. The reason for that is: If an AI or the POC is following the racing line (ie. passing directly through each waypoint) and another AI is along side it, the second AI will not reach the waypoint without having to stop or turn around (not desirable!). Which brings is nicely onto ...

Avoid collisions with other vehicles: You will need two collision systems. Firstly a collision check system which checks to see if two cars have collided and performs whatever actions are necessary, and secondly, a collision avoidance system which looks ahead to see if a collision is likely to happen and if so take avoiding action. A collision may happen because a car has taken a corner too fast and slid into another. If that is the case it is unavoidable and can be ignored. However, a collision is most likely to happen when one car is on the racing line and another wants to be in the same place. Here you could say maintain as close a position to the racing line as possible without colliding. That would work well if the two cars were along side each other like at the start of the race but if one car was moving faster and wanted to overtake then it would fail because it would simple stay behind the first car. Which brings us onto ...

Move to an overtaking position: What I would suggest here (and for the case above) is that a second temporary waypoint is assigned for the overtaking car. Look at the vehicle in front and assertain the largest width between it and the edge of the track. Then place a new waypoint in the centre of that area. Once the AI has reached the new waypoint continue as normal ... which means asking "can the AI get onto the racing line?" If yes then steer towards it. If no then repeat this step again.
Of course it is possible that there are two or more cars ahead and there isn't a gap wide enough for the new waypoint. In that case the AI would have to reduce speed until it could overtake.

Move to a blocking position to avoid being overtaken: For a truely accurate AI, this would need to be taken into consideration. However, for a game it would be very annoying to hav every AI car weave infront of you when trying to get past. So I would say that when wrinting racing AI for a game this can (and should) be ignored.

Try to stay on track: You might think that this is already taken care of because of the use of waypoints. However, if an AI takes a corner too fast and loses traction, then it needs to rectify that before leaving the track. Either by braking or using oposite lock.

Drive back onto the track if the above failed: In the event of the above failing or an AI be forced off the road due to a collision then it will need to find its way back to the track. For this I would recommend using flow fields. To use flow field you would divide the game world into an array of small grids. Each grid holds a directional vector. When an AI leaves the track, determine which grid it is in and then you can read the directional vector from the array to asscertain which direction the AI needs to steer in order to get back on the track.

The AI must be beatable: It is far too easy to allow the AI to drive the best possible line at the fastest possible speed. Doing that will of course greatly annoy any player. You will need to include a random fluctuation in the speed at each waypoint (as mentioned ealier). You will also need to adjust the AI to give the player a chance. If it is too hard to beat your users will soon give up. Equally if it is too easy to beat there is no challenge. This isn't easy to get right but is achievable. You will need to adjust the AI's top speed. Reduce it if they are too far ahead and increase it if they are too far behind.

Finally, when creating the waypoints. It would take a lot of trial and error to determine the maximum speed for each waypoint. What I would suggest is to get you POC working correctly and then drive it round the track many (many!) times. Each time you store waypoints along the way including the speed and direction at each one. Then after each lap, check your lap time. If it is your fastest, then these waypoints are the ones to use in the game. If the POC leaves the track at any point then that lap is void. You could improve this system by splitting the lap into several sections and determining the fastest time in each section. I would also recommend allowing friends to try to beat your fastest time and use their waypoints if they are faster than yours because (painful as it sounds) sometimes other people are better at playing your games than you are.


Further reading:
Start your Engines A full book dedicated to writing a racing game.
AI Game Programming Wisdom There are currently four books in the series but volumes 1,2 & 3 have chapters dedicated to racing AI and are well worth a read.
I would also recommend the Game Programming Gems series of books. There are eight in the series (plus best of) and although none of them have any specific racing AI chapters, they all offer some very useful advice in all areas of game creation.

Good luck!



ScottyB
18
Years of Service
User Offline
Joined: 26th Jul 2007
Location:
Posted: 30th Sep 2010 15:17
Thanks for all the relies.
I've been checking stuff out but to be honest with you all I'm lost. This is harder than I thought.
Is there a way someone can code me up a sippet of code maybe a little demo to show me this stuff in action???
I really suck at AI and some help in how to program this in woould be greatly appreciated.
Thanks!
Gael
15
Years of Service
User Offline
Joined: 27th Sep 2010
Location: Athens .
Posted: 30th Sep 2010 15:40
We all suck at something until it has been sucked out

You could try , bringing the CPU Vehicle to the same terms as
the users vehicles.
For instance , if your racing track is flat create an array containing that data in 2 dimensions.
This way the cpu cars scan what is coming toward them as they move along .
As AI and game-being-harder increases you may allow CPU cars to , scan further , so adjusting speed faster , or "learning" the track as they go.
In short .. Implement your driving laws on your vehicles first
Build a little "test room" where you allow the cpu to play around
under these laws , so it understands and LOGS turning speeds , braking , how angle is affected etc.
When you have that logged . You have your drivers AI skills in.
So . To apply it , when the CPU Car meets , set turn for the first time , it wont come through perfectly , but , it will remember turn stats (angle,width,slippery) ,which will allow
pulling data accordingly from the logs , to turn efficiently next time.
Scraggle
Moderator
23
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 30th Sep 2010 16:57
You'd think by now I would've learned to spot the gimme da codez posts a mile off. Somehow this one slipped through the net.



Jambo B
16
Years of Service
User Offline
Joined: 17th Sep 2009
Location: The Pit
Posted: 2nd Oct 2010 12:44
Scraggle - yep, but cheers for taking the time to type your post above anyway. There are some very useful ideas in there!
Sixty Squares
20
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 2nd Oct 2010 16:48
@Scraggle: Your post helped me; I like the waypoint idea. I've bookmarked it for future reference


Guns, cinematics, stealth, items and more!
Plotinus
17
Years of Service
User Offline
Joined: 28th Mar 2009
Location:
Posted: 2nd Oct 2010 23:48
Likewise, still a very interesting post, so thanks. It is interesting how believable and complex behaviour can be generated using a few fairly simple tricks. I like the "temporary waypoint" method of having the AI overtake each other - simple, but it sounds powerful and flexible.
Scraggle
Moderator
23
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 10th Oct 2010 15:34
For anyone else that found my post interesting ... I would also like to point out that in Game Programming Gems 4 there is a chapter called Vehicle Physics Simulation for CPU-Limited Systems. It was written by Marcin Pancewicz of Infinte Dreams and is an excellent demonstration of how to accomplish arcade style top down vehicle physics with not a lot of mathematics(phew!)... well worth a read!



Login to post a reply

Server time is: 2026-07-22 03:51:23
Your offset time is: 2026-07-22 03:51:23