Racing Game AI develpoment opnions

Blitz3D Forums/Blitz3D Beginners Area/Racing Game AI develpoment opnions

Gladen(Posted 2006) [#1]
Hello All!

Firstly, I'm not wanting code...just advice. My median-term goal is to creat a sci-fi racing game (imagine flying motorcycles). I am doing very well at it and am amazed at how powerful BLitz3D can be when used properly.

What I need is the opinions of others that have gone this route before me.

For this racing game I am in the process of planning how the CPU controlled racers will act, move, and react in the game.

Here's what I want to acheive:
1) No preset and predictable paths
2) Each racing entity makes its own decisions(limited number of CPU controlled racers...maybe 4-6)
3) A dynamic reaction based upon the real-time factors in the game
4) A distinct personality for each CPU racer

Here's how I think I should do it (and have been experimenting with):

I defined each and every CPU racer personality as a subset of a type CPUracer. Each subset is called by name (Inky, BLinky, Clyde...etc [yes, i'm old and that's a Pac Man reference]). The type contains a preset 'personality' of variables that hold such things as how aggressive they are against opponents, how far off the center of the track they are willing to go, how much over/under the maximum safe speed of a turn they'll go, whether they like to race past an oppponent or push them off the track, etc.

The race track is loosely defined as it is a 3D world and the speeders (my flying motorcycles) can fly over objects. So instead of making waypoints, or importing in a pre-described path of racing, I made a 'median' line for the track. Depending on the 'personality' of the CPUracer, they will adhere to the median (more or less) or go off-path to meet their desires.

When the CPUracer is in the proximity of a hurdle to overcome, or a power up, they check their relative position and decide (based upon their judgement, reaction, and aggression values) whether or not to 'go for it' or avoid it.

When a CPUracer is near an opponent, they calculate whether or not they 'think' they should pass them, bump them off the track area, or take another action.

Another function generates how the 'think' they should pass (left, right, over, under)

I have created a bell-curve decision loop function that defines (in percent) the chance of them taking any particular course of action. this decision is modified by their personality variables. So if I have Inky, a peaceful CPUracer that just wants to race, his decisions will be mostly within the 'Let's just race' idealogy.....but with Clyde, his aggression makes him more prone to knocking other players into cliff walls.

Now each and every CPUracer also has a variable that tells them how far off course they are. When they reach a certain point off of the median of the track(predefined by their personality) they determine whether they should get themselves back on-course, or try to short-cut it to the track before the next checkpoint.

Likewise, when they get close to the player entity, they make similar decisions.

When no obstacles are around the CPU controlled racers guess the shortest path to the median of the track (based upon their personality) and go to it, plus or minus some personality-colored variances.

Overall, this gives, I think, a pretty definitive illusion of thought, decision making, and personality; as BLinky will go straight down the middle in a straight section of track, but hug the inner curve on a turn, and pass his opponents on whatever side he thinks is the shortest when he gets near an opponent.

Thus far, my experiments and tests have been decently cool and work, but I am wondering if anyone else has gone this route before and would like to give me advice on my strategy development.


Thanks


Buggy(Posted 2006) [#2]
That sounds amazing and comprehensive, and the only advice I can give you is to start thinking about a selling price for the game! ;)

Keep it up!


Damien Sturdy(Posted 2006) [#3]
I have implemented AI similar to this, it's alot of work, but the best route to take is the shortest- As in, I re-wrote my code, did things in the least amount of code, and the Ai was mroe believable.

When you get this working, post us a demo, We'd love to see :)


Nicstt(Posted 2006) [#4]
Great post imo, working on the AI for a board based word game.

Might have helped me some by saving on thinking time if I'd seen your ideas first.

Maybe someone will sticky this as is best breakdown I've seen for planning an AI.:D


puki(Posted 2006) [#5]
Well, in honesty, I would have done it with waypoints - even if it meant just using critical ones.

I've not gone your route before and my only thought is the track design. You may come up with a nice system that *breaks* when you start designing new fancy tracks - or, then again, it may not *break*.


Stevie G(Posted 2006) [#6]
Good idea. This IS actually a waypoint system already. No matter how you look at it you would have to store points to represent the center of the track.

An important thing to note is that while the median may give you a clear route around the track it will not necessarily be the quickest racing line so your AI may be easily beaten by cutting corners etc...

For racing AI I generally precompute the best line / approach speed for each waypoint based on the length of the previous straight / the sharpness of the current turn and the vehicles max yaw rate. Once you have that you can adjust each vehicle so that it picks a point which is offset from this waypoint by a random amount and with a target speed slightly higher or lower than the baseline speed. Factor in different braking / acceleration etc.. an overtaking routine and you have some very smart / realistic vehicles which will never take exactly the same line around each corner and at their best will be very difficult to beat.

Good luck with it BTW!

Stevie


_PJ_(Posted 2006) [#7]
inky blinky pinky clyde and sue?


Rob Farley(Posted 2006) [#8]
On Sphere Racer (my first ever blitz game) I used a waypoint system.



Very basic AI that looked pretty real as the opponents made mistakes. Also the computer couldn't do anything the player couldn't do. ie the player could only steer left/right, accelerate and brake. Computer players cheat and be able to go faster or anything.

Basically:
Which direction is the next waypoint?
Is +/- x degrees off the direction I'm moving?
If it's over a certain threshold then steer
If it's over a bigger threshold then stop accelerating
If it's over an even bigger threshold then hit the brakes

And that was the entire AI!

So you had 3 numbers to give each sphere a 'personality'

1. How far off direction before you start steering
2. How far off direction before you stop accelerating
3. How far off direction before you start braking

Very very simple, but worked really well.

I was going to complicate it so they'd try and get pick ups and avoid the other racers... but quite frankly... it wasn't worth the effort and seeing them smash past other racers looked cool, and because it threw them off course when they did it made the AI even more believable.