Hi all. I would like to know which AI method is common to control cars (steering and acceleration) in advanced racing games like need for speed, asphalt,blur,etc?
PID Controller, neural net, Reinforcement learning, etc
To build a modern racing game, you still want to start with the basics like waypoints, steering behaviors, and such. You can layer other things on top of that to make the racing game more advanced. For example, utility AI can be useful for balancing various constraints. You could build a utility AI solution that determined aggressiveness based on current position in race, time left, and if there are other cars nearby.
Beyond that, you can add things like neural networks. Just keep in mind a neural network is merely computer equations generated by data. The quality of your data and how you use the data will determine if a neural network is useful for your game. You could generate a data set by having the computer randomly do things and record the results. For example, when entering a specific corner, the car will have a position, velocity, etc. You could have the training program randomly try different drive lines and throttle positions, and then record all of that data (including outcomes). Then you could train the neural net based on that data. Once trained, the neural net could quickly determine how to handle the specific corner based on position and velocity.
When using neural networks, remember to double check the outcomes. A neural network might decide to do something that looks very stupid to the player but delivers the best laptime outcome on the track. For example, maybe the computer would slide the car sideways in a specific spot, hit a mailbox, flip the car, and then land in a spot that shaves a tenth of a second off the laptime. If all of the AI cars choose to do that every lap, players would think the AI was completely broken.
At the end of the day, always remember the goal is to have the AI driving the cars to seem like real people to the player. The goal is not simply to reduce the lap times.
Machine learning is hardly ever used in game ai. Because you already know the answer to what is the best outcome and how to get there. There is nothing to discover you have perfect information.
So most ai is simply hand crafted logic to make it do what you think works best. To get more life like behavior, the most common approach is semi random numbers. Utility ai is a fairly refined approach to this.
The ai forums on gamedev.net are pretty good for ai stuff. The moderator is one of the best in the industry does work for big name games and regularly speaks at GDC.
Going back a few years now, but I think the approach used in rFactor (Image Space Incorporated) is a fairly common one.
They used a waypoints system to provide an ideal driving line for the AI.
This driving line is generated in development by someone actually driving around the track and the best lap being recorded as a series of waypoints.
Each waypoint also stores the speed the car was travelling, along with other useful data.
At runtime, the AI then looks at which waypoints are coming up to determine an optimum speed and position on track.
They also had alternative driving lines for wet weather, as I recall.
Another level of AI is then used for car avoidance and overtaking, but starting with the simple waypoint system is a good method to get something up and running that looks realistic.
Can confirm. I worked with the ISI engine on a budget title way back when. When the real person was recording, the AI engine would plop waypoints along the driving line. Each waypoint would also store the elevation, and the min/max left/right distances for that section of the track.
I think these approaches have been used atleast 15 years ago. They are the first approaches we can say!
but I do not think that modern racing games use these simple approaches like recording bunch of human driving with different cars in different weathers!
If you use waypoints, you need a controller to control acceleration and adjust car steer. Simple controllers like PID controllers have many problems to adjust correct parameters, Another one is fuzzy controller.
You say that games like need for speed does not use above controllers and use simple controllers? or record human behaviour?
I don’t know what modern racing games are using (and from the few minutes I spent researching it appears that they don’t really share that information either) but Unity showed off a racing game at their machine learning talk at GDC 2018 and the way they described it made me think of reinforcement learning.
I thought you’d respond with that. I was just confirming that that’s how the ISI engine waypoints were authored, and that it’s definitely a good start. I agree with everything everyone has responded with. But any AI effort is going to start with a data set for your AIs to consume, and that’s a good way to do it. You’ve got to start somewhere, and most modern games don’t use just one AI system/technique/algorithm for resolving solutions and/or making them behave like humans. As @ShilohGames mentioned, AI is often layered until you get the results you want.
Start with a simple base and work up from there. Start with a series of waypoints along your path, have the AI objects follow that. You can then add an offset in the local X to those AI objects so they can ride on either side of waypoints (in the left or right side of the path). Next you might give the AI some simple “intelligence” to avoid other AI objects or the player. You might approach this with raycasting out from the AI object in the local Z axis and out 45 degrees on either side (could do extra 90 degree checks out to the sides too). You can put these raycasts into a method that is only triggered by being within a certain radius of other objects (i.e. using a sphere trigger or cube trigger). Next you might make the AI objects aware of some of the current properties of the player. These could be the player’s speed around the path, the player’s current race position, the player’s engine torque/power or any other performance related aspect of the player. Another enhancement is to make “zones” around your path that tell the AI to behave a certain way in straights, or behave a certain way in turns. Basically your AI needs a basic knowledge of what’s going on in the world around it to act semi-intelligently.
You have to think about this how it works in the real world. Race car drivers don’t experiment out on the track, they don’t do unexpected things. It’s all very predictable in the real world and you tend to see the same things happening over and over again, even in different races. They drive a best line, they brake going into a turn and start accelerating again at the apex, they avoid other drivers, they overtake other drivers when the coast is clear, they avoid walls. It’s a pretty simple breakdown when you think about how race car drivers operate in the real world. There is absolutely no need for you to attempt to integrate emotions, physical condition of the driver, or the faulty aspects of being a human being into your AI. It’s just over-complicated for a racing game. Maybe this would be a neat endeavor for AI characters that the player would be talking to, interacting with in first person.
Thank you all.
For completion, I can define several paths that cars can change their path (switch between paths) when they see obstacles in front or can deviate from main path to avoid collision and then return to main path again but I asked “how can a car return to main route?” With simple controller like PID controller or some simple distance checking and lerp.
I think I can not use position lerp (between current position to target position in the main route) if I use rigidbody and realistic physics because I need to change torque and force (or velocity) but not position.
You would need to think in terms of steering behaviors instead of just lerping a position.
Exactly. The AI inputs should be in terms of steering, braking, and accelerating, and clutch if you are going to support that. To blow your mind more, if you’re making a game anything like with stock cars or even dirt track racing, you have to consider that they actually steer with the pedals, not the wheel when going through turns. It’s counter intuitive, but to get competitive AI on ovals, you have to take these things into account.
Yes, all the cars(player and AI) should have the same input and output(track and racing condition as input, steering and acceleration values as output). As the computer can’t see the track as the player, you can use points to show where the car should TRY to drive, and your AI will calculate the best acceleration and steering.
I’m researching this topic for some time, there isn’t many articles about how big games do it, but I managed to create an (not done yet) AI that can drive…
In my game(in development), the behaviour is simple but works: my AI gets the actual point position. if the car needs to steer to the right(the car is on the left of the racing line), it just do it. I also watch the next way point, if the car can’t steer to achieves the next way point, the car starts to brake.
For overtaking or avoiding other cars,I just creates some RayCasts, if there is something needing to be avoided, the car avoids. if the track is clear, just steer to the normal racing line.
(Obviously there is other factors affecting the AI decision).
I hope this helps, at least to start :).
I said the same, we can not use simple (from deviated point to target point) lerp!! so we need a controller to control steer and acceleration like PID! or simple distance checking.
I’m not sure if you were responding to @diegomendes , but if you were, he’s not suggesting to do a simple lerp. The waypoint path basically influences the steering and acceleration/braking inputs. You cannot lerp and have a fully-functioning physics system at the same time.
ML is the fun kid at school right now and every big studio is giving it a go. I’ve done a few racing game AI’s and my approaches are all waypoint based. Each node sits at regular intervals along the track (easy to automate) and describes the track width, elevation, etc.
From there it was somewhat trivial to determine what is coming up next and adjust acceleration and so on. I did not need to faff around with pid controllers or anything like that. I didn’t constrain the cars to the waypoints, merely used the data, introduced some gentle random variation…
Within 10 mins of number tweaking, all my cars were happily barging into each other, dodging and sliding around. I think, for most cases where you know the track in advance, the simpler option is the most rewarding and fastest to develop.
Sorry about that. I read it, but forgot.
I’m such an angel today. Pat, pat.
Waypoint or splines for pathing. (go in particular direction)
Steering behavior for steering around other cars and obstacles and keeping position in relation to other cars etc…
Neural network for low level things like preventing crash with other cars, left right steering, controlling speed on curves, accelerating,breaking etc…
Take into consideration that I have not created any serious AI for racing car, just some boids with pure NN.
Dude. Check the thread’s start date.
I don’t think it’s one of those threads that expires. AI is always interesting to talk about.