GameDev Blog: Goblin Rules Football #7: Single player… works? (sort of)

My last post was my first steps toward a single player mode, and I successfully made it so the AI player could choose a coin in a coin toss and pick to either kick or receive if they won the coin toss. Pretty simple stuff, but not much of a game.

I figured it would be a lot more difficult and time consuming to make the AI work during regular “game play” of the game. And, well, it was difficult (for me) and it took a while, but I had a lot of spare time on my hands this week so I was able to add a lot and I can now play a complete game against the AI! Check out this sweet video below

Wow! Whoa! I was able to mercilessly crush the AI 26-7, even scoring a touchdown in the last xtra-time to really rub their nose in their bad performance. But, let’s see what had to be added to make the game work:

First I looked at what AI stuff I already had which was for the 1v1 mode. The “AI” would do things with goblins that weren’t “Selected” already. When I played as is before this week, the AI would move around two of their goblins, but not the third one they had “selected.” If the AI had the ball, the ball carrier was automatically “Selected” and wouldn’t move. So, the first step was giving the selected goblin something to do. When they have the ball, run toward the endzone! When they don’t, find the ball and chase after it! Find a goblin to punch! Just do something! When the selected goblin doesn’t have the ball, the AI just uses the same logic as it does for the other two goblins. When they are the ball carrier, though, there is a bit more to consider, such as the following:

  • Detect nearby goblins and differentiate between teammates and opponents
  • When should they kick downfield? Near their own endzone?
  • When should they pass? When opponents are nearby and teammates are open? Add some “fuzziness” so they don’t always pass when an enemy gets within “x” distance of them?
  • Detect when your near your scoring endzone and dive
    • If no opponent goblins nearby, move toward center of endzone to make the kick easier
    • if opponents are nearby, dive as soon as safely possible to score
  • How to put “distance” between the ball carrier and the nearest opponent
    • If an opponent is near and above the ball carrier, the ball carrier should adjust their desired position to be “down” to increase the distance between them and the defender
      • weight this based on how close the defender is, and try and take into account multiple defenders: get the “average” direction of defenders and adjust the desired position accordingly

All of that is now “in” the game, though it all definitely needs some fine tuning. The AI still has a quick trigger on passing the ball, and the AI is much better at passing then me!

After I got the selected goblin to do something, I then had to make sure the AI knew what to do during the other non-gameplay portion of the game, the kick after attempts. If the AI wasn’t kicking, it was easy: Have all goblins run at the player’s kicking goblin to try and block the kick. How to kick the kick after attempt was a bit more involved, though. I had to have the AI figure out how hard the kick was and to adjust how far back they’d kick to make it easier. So, the AI moves their kicker back until it reaches a desired kick difficulty, or until they reach a certain percentage of the kicking goblins max kick distance (you would need to get 100% kick power to make a max distance kick, which is hard, so as a player or as an AI you’d want your kick to be 5-10% closer than max or something on hard kicks).

Next steps…

I want to continue working on the single player (and 1v1) AI. First, I need to add some logic so the AI can make their goblins sprint. Part of the reason why I beat the AI pretty badly is that they never sprint, while I do, so I can move faster than them. My first attempts at the AI actually had the AI kicking my ass every game, like I’d lose 35-7 every time, and that’s when I realized they weren’t being affected by slow down modifiers like I was. After I fixed that, it was much easier. Speed kills!

I also want to make it so the AI can use powerups. The AI can pick up powerups, but doesn’t know how to use them. Need some logic on when to use what powerups, which will probably be hard, but maybe I can figure it out. If I can’t, the AI will just randomly use powerups and whatever at least it is doing something.

I also want to add some new “tasks” for the non-selected goblin AI. I have the ball carrier kicking downfield, but the AI is always “getting open for a pass” and behind the ball carrier. There should be some way for the AI to anticipate a kick downfield (if they are near their own endzone) and start running downfield to chase down the ball early. This would be particularly good if the skirmisher (the fastest goblin) tried to do that since they are best suited to get the ball fast and make a break away for the endzone! Though, I’d also want something for the defenders too. The defending skirmisher detects that a kick downfield might happen, and starts moving further downfield to catch any kicks that might occur.

Man this is starting to get complicated…

Smell ya later nerds!