Artificial Intelligence (AI) for Super Truckin'With AI comes many complications. We not only wanted AI for racing, but we wanted it for all of our game types. I would like to go over what we needed for the game type, what problems happened and how we battled it. If you'd like to see some code let me know! Want be in the beta? contact us!
https://twitter.com/in8bitgames -Soccer-Need: Each AI follows the ball to knock it into the opposing goal.
First thing we needed to add was how to track a single way-point. This is pretty standard and allowing our trucks to follow a way-point was pretty straight forward.

You want to hit a ball... you make the ball the way-point and your done. Right? Wrong! this will allow the AI to just smash into the ball with no clear direction. The soccer field will be like a 5 year old playing pool and smashing the ball off every wall in hopes to make it in the pocket.
So we thought about adding direction. Adding this was a little bit more complicated, we had to basically get the AI to get behind the ball and aim it towards the goal. Math cant do this? or can it! We need to know the goal and ball location, the direction in which to hit the ball towards the goal and some math magic to get the arch to go around the ball. Our first test results with this logic.

Whew... we started playing with it... and wow... this made it a lot harder to play against. They would steal the ball away from you and try to knock it towards their goal. It is not perfect but it works pretty well.
The problem with this approach is it acts as if the target is stationary for that moment in time. By the time the next update happens the trajectory changes. This makes the AI not as accurate when the ball is moving quickly.
That is all it really took to get AI working for soccer. Can we make it better? Oh yes, there are many ways to improve it. We could look at the trajectory of the ball, and speed of the vehicle and account that in the algorithm to where it needs to hit the ball. Eventually we will add this but for now the AI is already pretty challenging. If you guys want it to be harder then we wont want to disappoint.
-Hay-Need: Each player tries to go for the hay and knock it out of the arena
We now have single way-point navigation, all we need to really do is turn off ability for aiming it towards a soccer goal. Sweet! Done and done... until we tried it....

They became experts in finding the hay, and knocking it out before you ever have a chance to get to it as well. They were impossible to play against and it wasn't fun.
So we added Object avoidance Which i will explain later. not only are they trying to always hit the hay, but they are actively trying to avoid it as well. This nifty trick made them just easy enough to be playable. They don't score every time they get the hay just like a real player would.
-Racing-Need: Each player follows the track.
So adding onto the single way-point system we already have. we needed to add more to be able to allow the AI to follow a track. Awesome, easy enough. Just make the way-point a list of way-points and when it gets close to the current way-point make it go to the next one.

So now we have an AI set up for our racing level but this is when we saw problems we were not expecting.
The problem we had with this approach was we have several areas that a vehicle can get knocked into (such as the quad jump and hills they can fall off of) and how does the AI react when this happens? Right now they will keep trying to get to the next way-point and get stuck on a wall. So how we battled this was to implement zones. This allowed the AI to validate that this is the zone it should be in, and if not to react by either going to a new way-point or follow the track where it dropped like a normal player would.
Bad behavior:

Good behavior with Zones:

AWESOME! it looks like we have a way-point system and a zone system that the AI follows and if knocked out of either system it can figure its way back. We now have pretty amazing race AI.
-Object Avoidance-I believe this needed its own section because we have now integrated this behavior in each of our AI's.
• In every Level (especially racing) the trucks would pile up leaning into each other as they go to a way-point, ball or hay. This caused the trucks to crash and slow down and didn't look fluid. I could easily pass them when they are in this state.
• Early tests on the Soccer level you would see the vehicles stuck against a wall because they were trying to go through the wall to get to the other side of the ball.
• Testing the hay level they would pile up more than hitting the hay as well as clipping edges of jumps and causing them to lose control all the time.
The answer to these issues is to make the cars see. we basically gave them eyes so that they can listen to things around them and react. This changed our game. This made the AI react in ways that were more what a player would. It felt they were more human when obstacles popped up.

we added ray's in front of the vehicles that listen to touching objects such as cars, sides of jumps, and walls. Left ray is touched turn to the right, right ray is touched turn to the left.
We could add the barrel mine to the things to avoid but this gif wouldn't have been as awesome.
It has been a lot of trial and error. Testing constantly with and without people. We think we have solid AI for each level and each having completely different behaviors. Are we done with the AI? nope! We do plan to constantly improve and balance each level to make them as fun as possible.
Thank you guys for reading and check back often for more awesome posts! If you guys want more information about anything else we have done please let us know!