Creating Racing AI

This is the main thing I was dreading when I decided to make a kart racing game, but I have to tackle it at some point- artificial intelligence. I’m not really sure where to start, and there’s apparently a lot of different methods of implementing it.

It would help if someone could suggest different AI methods or post samples, so I can determine which would work best for my game (the WIP thread is in my signature).

If it helps, here is what I’m looking for in an AI system-

-no rubber-band AI. Not sure if that’s supposed to be easy or difficult, but it’s overall frustrating and unfair to the player. coughcoughMarioKartcough

-I’m looking to have about 8 karts running at once (including the player). [I remember SolarLune found a method of looping logic through multiple objects for a massive speed increase- hopefully I can find a way to implement it.]

-I’d like the karts to also use the vehicle wrapper, to ensure that the player kart and AI karts are all subject to the same speed/turning/orientation constraints.

-AI karts not only have to follow a track, but have to pickup and use power-ups/items appropriately (ie. picking up a projectile weapon and attempting to shoot it at another kart).

-I’m emanating a similar style to Diddy Kong Racing (N64) for the art style and mechanics, so this may also help with determining AI.

I hate to bump this, but this is really necessary for the game, and I have a deadline. I’m not looking for someone to post a full blown AI system, but just suggestions or links to different methods of racing AI.

As far as i know, there are two main types of racing AI. a good place to start would be to figure out which one works best.

The first type would be the “dumber” of the two, this is a node-based sort of AI. it uses empties that are placed around the track to find its way through. it does this by tracking to the next empty on the track.
DOWNSIDES:
1-Causes “rubberbanding” where the AI would attempt to get to the “node” or “point”, but if done correctly it should be possible to fix

2-It takes longer to create new levels or tracks and makes it VERY difficult to add in a “track editor”

3-this AI only has one path, so if your doing something where for example, a bridge falls on the track the AI wouldn’t be able to avoid it

UP SIDES:

1-its easier to learn how to make this type of AI

2-it saves Framerate over the other one

The second one is way more complex, and this is one that could actually be called “AI” This one uses ray, radar, near, or collision sensors. this one can be made basic enough that it uses only logic bricks, or so complex that it could take hundreds of lines of code(this is based off how complex you need or want it to be)

DOWNSIDES:
1-depending on the complexity this one could have a lower framerate, and may be made even worse by having multiple AI

2-this one takes longer to code and impliment but once you have it made, it can be used on any track(as long as the tracks are basically setup the same) ie same propeties on walls and such.

3-This one is also harder to get looking “smooth”

UPSIDES:
1-Because this one is so flexible, it can be used for almost any style of racing.

2-This one can do alot more than the other one, if you wanted im sure there could be a way to implement pathfinding, collision avoidance, etc etc.

3-this one does not “rubberband” so it makes it less frustrating for players.

thats all that i can think up for now, but im sure theres more advantages and disadvantages to both of them, hope this helps

This may have some interesting stuff?

Actually, there is a third method for AI.
you can create a path-mesh, and use that.

In theory you could use a script like this to get you to the path directly to the car,if find a way with this can make more path
(in GT4 think is much similar with 5 path )

####
####
import bge
c=bge.logic.getCurrentController()
ob=c.owner
sens=c.sensors["Keyboard"]

if "startPath" in ob:
    ob["timer"]-=1
    if ob["timer"]=0
        ob["timer"]=60
        pos=list(ob.worldPosition)
        ob["newPath"].appendXXXçJKçOJKO(pos) ##save the position on external file 

if sens.positive:
    ob["startPath"]=1
    ob["timer"]=60
    ob["newPath"]=OKJOKçKOKç
####
####

need of python expert!

great the explanation of kendrick1397!

I have been making a racing game too, and AI is a big consideration. These links may help:

http://www.red3d.com/cwr/steer/PathFollow.html

http://www.red3d.com/cwr/steer/

Attached is my node based AI based on logic (which I made a long time ago, currently I am making a Python/ logic hybrid). I have also attached a very old steering system that uses rays and radar too. I hope you find them useful! They are not amazing, but they are just two of the fifty small tests I did (and still do!)

My thoughts:

It does not matter what the most technically ‘correct’ solution is: the only thing is to make your game fun to play. It will be easy to intergrate some AI decision making into your game- you may wish to have simple functions like (pseudocode):

if health < 20
look for objects with ‘health’ property
track to

It is also possible to make a waypoint based AI that also has rays. When a ray hits an obstacle, it can be instructed to steer around it (I have tried this in logic, and it will work).

I think waypoints would be easier and better (in my experience, anyway). Steering with rays and radar is possible (I have a top secret system that I need Python for that may be ideal:evilgrin:) but waypoints allows better track layouts (as you are telling the car where to go). Rays and radar are problematic as it is like being blind tapping a cane around- thus it is a more reactive system that only steers when it is about to hit something- it cannot develop a racing line as it is pinballing off the track sides. There are also other problems: which way to turn if you detect a track edge, hitting an edge straight on (again, which way to turn?) certain shapes (like L shapes) can trap a primitive rays/radar AI into turning the wrong way. Been there, tested that!

Remember, you are not a full time game developer- find a solution thats simple and fun and do that…use Blender and make small prototypes to see what works the best for you. Last time I played DK racing (or Mario Kart) its all about having a laugh- if your game can do that, screw the rules!

Lastly, most racing games these days use pre-computed ideal racing lines, so in essence they are a hybrid of waypoints and auto steering.

And good luck!

Attachments

AI_VER3ex.blend (1010 KB)AUTO_STEER_RAYS_AND_RADAR.blend (562 KB)

Awesome, thanks for all the suggestions! The waypoint idea sounds pretty good as opposed to only using rays and radar sensors (@Rubbernuke, I liked the analogy of “blind cane-tapping”). It’s a bit late now, so I’ll have to experiment with these tomorrow. Thanks again!

ahah…cool! Rubbernuke! I like your blend files!

But too many logick brick, how do you manage?

MarcoIT: Thanks! I learnt the basics of this from a tutorial by a BlenderArtists member called Mmph!

This is the disadvantage of logic, as it gets messy very quickly. Here is a more recent example that I am working on that uses a mix of very simple Python and logic blocks to make things simpler.

In the first .blend, the main bulk of the logic is now Python ‘if’ statements, and the only logic bricks required are those to increase properties and detect collisions. Hope you find it useful.

By the way, if you hate Python, you could just use expressions like the second example. This is as far as I could streamline a logic only approach, and it uses less resorces than the Python/logic example.

Attachments

logicsteer12.blend (450 KB)steernopython.blend (333 KB)

Yes Yes :D… that they would be a python? jokes? :wink:
I had to do a real python!:smiley:
I can not resist! :eek:

seriously, if you need to clean those brick games, paste it ,i transform!
is a good exercise :rolleyes:

Attachments

steernopythonVERY.rar.blend (53 KB)

ahm,not, the gravity problem i had leave from edit mode(bug?)
if is usefull can use worldLinearVelocity[2]-=9.8
because is problematic the gravity default
hi