- Home /
Racing Ai? long read
Hello. I was wondering if someone could shed some light on how games generally base ai for racing... Like what is the logic? Im not asking for code, but the idea behind the ai they use. For example, lets use a simple racing game like Nintendo 64s Diddy Kong racing (yes I still play it :). The racers move indepently and can be attacked, bumped, stopped, etc and still figure out how to get back on track and in the race. I know of pathfindg for unity in general, but from I understand it basically uses a waypoint system. What I am confused about is do racing games use waypoints like this, or are the racers follwing the race track some other way? If they do use waypoints, do they have to set up different waypoints for EACH different racer to follow? It doesn't seem so from playing any racing game, because with all the bumping and attacking going on to shuffle the racers, the racers still move uniquely around.
I am trying to build a racing game using highways I built both in unity (drag n drop highway pieces to build road) and pre built whole highways from 3ds max. I would like there to be random npcs going along the road at random speeds that if you collide with, will dodge or get back on track and keep going.
I have this currently set up with a very basic waypoint system- I simply made a waypoint string of objects along the highways for specific npcs to follow.
var WayPoints : gameObject[];
var curPoint : int;
I have it check 'WayPionts[curPoint]' while doing transform lookat and moving forward until it touches the current point by trigger, then I just do curPoint +=1 and rinse and repeat
This works, but to have multiple npcs I would have to set up mutiple, unique waypoint trains for each one. Not only is this tedious, but it's very unrealistic- each time you play you see npcs going striclty along some SAME path line.
I thought I could get around this by randomizing some of the waypoints during runtime in each npc's waypoint string, but it still looks too uniform.
I had an idea that maybe I should use bones and animate them going along the road in 3ds max, then in unity I could just child a racer to the bone, but the problem with this is that it would still be too uniform. I don't want the players to notice any patterned movements. I need randomized, free thinking ai.
Is there a better/simpler way to do this? What is the common ai logic for 'travelling/racing' npcs?
Thank you for your time and any advice
I'm not an expert on AI, I'm learning myself but I'll try anyway giving some suggestion so maybe I get something for me too along. Well for your situation surely waypoints are a game breaker, once a player learn hem you basicly can always win the race and I'm pretty sure other racing games doesn't use waypoints.
What you should try to do is to give a path for racers to go on freely, Unity Pro have nav$$anonymous$$eshes basicly are generated meshes of where AI can go around, the tricky part would be to make the racers know when facing the wrong way.
As for avoiding player or other cars you can probably go with raycasts, no idea if is ideal performance wise as you would cast multiple raycasts from a racer to multiple directions. Alternativly you can try the free plugin Rain Indie, which you can find here:
http://rivaltheory.com/rainindie/
You can setup behaviours and pathfinding without requiring unity pro, still won't make what you are looking for out of the box, but should be a sppeding hand.
"a simple racing game like Nintendo 64s Diddy $$anonymous$$ong racing"
were you kidding there man? That probably had 10 engineers working on the AI alone for a year!
I've never written a racing game, however, i think I'd set up way points that define strictly the centre of the track. If I know how wide the track is, then I can generate at run time random waypoints for the bots to follow.
Answer by Fattie · Jun 09, 2013 at 11:35 AM
Just FTR. One of the first things you have to do in an racing AI system, is build software that automatically finds centrelines, that automatically finds the centerline on your road concept. In itself that is by no means easy, you can google around various papers about it. That could be a good starting place.
I'd also suggest, I guess it's pretty common to have different "paradigms" as you nip around the track. So, on a straightaway, the whole "paradigm" of the AI driver is quite different (more focussed on overtaking and stuff), whereas on or near a corner it is completely different, and possibly in an S or something it is totally different again.
What you were saying about different waypoints ... try having wayLines which are perpendicular to your centerline. (so essentially that means two points, one on each side of the track.) Just pick a random point along that wayLine, each time for each car.
That could give you a step ahead, maybe that will help. Hope it helps!
Thank you. I have a better idea now and will look into it.