Smoke and Mirrors

Welcome back!

Fredrik here again, and this time I will bring you a peek into the design process of the AI in my game. As the title suggests, AI is usually not what you’d think when you experience it as the player. For instance, in our game, we struggled a lot with the AI even though it’s part of the core mechanics of the game. The AI is supposed to be what achieves the aesthetic of belonging in our game. You are supposed to feel like you belong to a swarm and any individual is less important than the swarm as a whole. Based on the concept that is achieved through the use of a formation to control all of the swarm and having the bees behave individually when not in formation.

To achieve this individuality I decided that I wanted the bees to move around somewhat randomly while not in formation and decided upon having them find a random spot at a distance between a random interval and move towards it somewhat slowly and once it’s reached within a small distance of that target it would find a new one.

AI_Movement.gif
This is what that looks like

I even have some basic avoidance code in the game so they try to avoid each other and the player if they get too close. This is done through a child collider of the AI bees and through adding the inverse vector of the colliding bee before computing the final movement vector. In addition to this, the AI bees also detect enemies in front of them while not in the formation and fire based on a cooldown, this is done through the usage of raycasting.

The second part of the AI is the formation, this had to be done properly as it would be the main mechanic of the game. The way we have it set up right now, which is subject to change, is that the player has a list of child object around it that the bees constantly move towards at a quicker pace than while not in formation, those are given to the AI-Bees through the use of two arrays, one for the bees that is stepped through and one for the formation positions which is handed out to the bees. In addition to this they also during this formation fire as the player fires. This is done through a similar method, stepping through the array of bees and calling a function to shoot on all of them.

AI_Formation.gif
This is the formation in action

As you can see the formation is draining the honey at the bottom of the screen which is the main resource of the game. When the formation is inactivated the bees go back to the position they had before the formation was activated.

In conclusion, as I said at the start, creating AI is not necessarily what you would expect and most of the time it’s just fooling the game to making it look like it’s doing what it’s supposed to. The bees aren’t smart enough to know where to go or any will to do anything at all, it’s just randomly selected constantly to create the illusion that they behave somewhat organically.

But as long as it does what it’s supposed to then it’s good enough for now.

PS: Credit to Adam Olsson, the other programmer in the group as the bee AI was a joint effort, he did most of the groundwork.

2 reaktioner till “Smoke and Mirrors

  1. Heya Fredrik,
    Well done on the post 😉 I really liked the use of gifs to easily give an overview of the features you’re talking about. Otherwise I think it would have been hard to visualize the avoidance behavior (or should I say beehavior :P). The game is also looking great btw, I really like the fluidity in the bees’ movement.
    But when it comes to the movement I do have one question. You explained that the bees select a point somewhere near them to move towards once they have reached their current ”waypoint”. What I’m interested in knowing is if you did any checking to make sure that they won’t move off the playable area? I guess you can always call them back using the formation function though, so perhaps it’s an issue you guys chose to ignore? If you didn’t I’d love to hear more about how you accomplished that as I feel having all bees on screen at all times would add to the ”belonging” theme of your game.

    Either way, fantastic work so far. Keep it up 😀
    //Alexander ‘Pawn’ Peck

    Gilla

  2. I did solve that issue at some point, I do not recall if it was in at this point however since it was a while ago. I think I solved it by having the bees compare their targeted position to a minimum/maximum value of their allowed area. Thanks for the comment m’dude ❤ 🙂

    Gilla

Lämna en kommentar