Hello , i would like to know what algorithms are used in racing games.I want to develop competitive opponenets so the simple A.I. in the Car Tutorial is not enough.
I’ve searched the internet and a found that A* and path finding algorithms are suitable for this problem.Is that correct? Should i start implementing A* algorithm in my game or this would be just a waste of time?
Finnaly,do path finding algorithms need waypoints just like in the Car Tutorial? or they use other methods?
I don’t think A* is a good fit for racing car AI at all. A* is more suited to an environment where there are multiple routes around the environment, and the AI needs to be able to decide a route from any Point A to any Point B at an arbitrary time.
What I usually do for race game AI is have a simple set of fixed waypoints along the track centre - say about 100 or so - and simply have the cars steer towards the waypoint marker that is ‘n’ steps ahead of the one that has most recently been crossed. You adjust ‘n’ based on the speed and severity of your corners.
You could also then make your cars brake or accelerate depending on the difference in heading between the current waypoint, and the one that is ‘n’ steps ahead - because by comparing these, the car can tell if it’s approaching a corner.
My assignment is to build a racing game.I had two options: make it network-multiplayer or implement some A.I. algorithms.Since i had some problems with the network i decided to search some A.I. algorithms.
Your idea is very good but my teacher asked me to search and implement “advanced” algorithms.
I have to make this assignment in order to get my degree from the university(I do not know the exact word for that in English ) that is why what you propose is not enough
The “simple” AI steering algorithm works really well. Unless you find an example of where it fails, there is absolutely no point in complicating it.
I would look for more complicated algorithms in other areas. For example:
Many race games use a simple technique called ‘rubber banding’ to keep opponents close to the player (to make sure that players of all skill levels get some interaction with the AI). This algorithm can be rather obvious to the player and also has the nasty effect of making a player’s mistakes towards the end of the race far worse than mistakes at the start. These are obvious disadvantages that beg for a smarter AI algorithm.
That’s just one example, there are many other options, depending on what your AI actually do during a race.
All an AI needs in a racing game is an idea of the best line to take at what speeds and collision avoidance.
For a racing game I made 10+ years ago for the former I just drove the track myself and had my car automatically drop invisible waypoints onto the track. These defined the “ideal” line that all AI cars would attempt to follow.
A more interesting approach these days would be a genetic algorithm. Let the AI cars try their own driving approaches randomly with massive retrials and cull the split times that fall behind.
I was thinking of a simulated physical grounding + genetic algorith approach for a car racing game recently.
Create a value based on what degree of control the car has (in regards to the physics) and how well placed on the road it is. The closer to “control” and the more of the car that is on the road the better.
Then use a second large collider around the cars, perhaps make a half sphere object and apply a mesh collider to it, have it move and tilt etc. with the car. Put some triggers (invisible) near the edges of the track and it can then determine the distance from the car to the TriggerCollision.
Have cars attempt to adjust direction and speed accordingly, in an attempt to increase control and maintain the entire car on the road at all times.
In order to have them plan, have an invisible “ghost car” race slightly ahead, which is recording it’s values but not attempting to do anything about them.
So all the car has to do is adjust itself in a way that it would expect a better result than the “dumb” ghost car.
Then from this have the best (3?) values for certain points (corners would be good) stored along with the times they acheived to reach that point.
You would then need to adjust the wieghts for cars who next race on the track when they attempt to correct according to the “ghost car”. “Evolve” them in a non-random manner in essence. But start with randomised values. Survival of the fittest.
So they will try thier hardest at first, but be very poor, they will likely drive slowly to maintain control and stay on the track. But only those patterns who get faster and faster times will be used, which should hopefully match the Human.
The only thing then will be to make the way the cars work out how to adjust based on the given wieghts complex enough that they can actually drive the car.