General presentation
In this second activity we have practiced with the movement of agents in Formation Motion and Flocking , and decision making with behavior trees , this time with writing code in C#.
ACT 1: security patrol
This first activity has surprised me how simple it has turned out, since I asked ChatGPT (link to the conversation in the webgraphy) to make a suitable script for my scene with the parameters mentioned in the GitHub of the subject and it gave a decent result at the first attempt.

As in the previous activity I configured the patrolling agent correctly, basically what I did was create several copies of the guard (changing the color of the texture to violet to differentiate them), but without motion scripts and I grouped them under an Empty that contains the Formation Motion script component. I have configured the script so that it can enter the formation figure dynamically.
ACT 2: insect hive
I’ve decided that my hive of insects will be a swarm of bees and a panel like FlockManager (it’s not the most original thing in the world, I know, but I found a model of a very cute bee that I couldn’t not use).

For this activity I have started from the code offered by our professor on GitHub, but I have made several modifications with the help of ChatGPT so that the behavior of the swarm is more natural and more controlled. Mainly, what I have done has been to add a maximum radius from which the bees can move away from the hive and I have increased the values of the vectors quite a bit so that they all have a more energetic movement. In addition, I have added alterations to the vectors so that they move more randomly.
ACT 3: flocking leader
3.1. Behavior and movement
Firstly, in this activity I tried to use Muse Behavoirs in version 0.11, but it turned out to be extremely unstable (in addition, the behavior of the other agents was unusable for some reason) with Unity “crashes”. In its version 0.10.1. (recommended by our professor) has given me multiple errors when loading the project, possibly due to the lack of components of the most modern version.
For these reasons, I have decided to proceed with the implementation with Behavior Bricks . This asset at first glance seems more complex and “rough” than Muse Behavoirs, but hey, it will do. The first thing I did was follow the outline of the old notes of the subject a little , but these were for a behavior different from the one we want for this bee, so I asked ChatGPT to make some modifications in the script of the condition “Is Cop Near?” and also in the AI logic tree.
The condition script must be placed in the “conditions” folder of the BehaviorBricks asset for the editor to detect it.

3.2. Monitoring flocking
Unexpectedly, the most challenging part for me was to make the flocking be the leader bee when it was required. It was thanks to the Unity AI Swarming Tutorial (Stephen Barr, 2018) that I managed to incorporate a simple logic that made the LeadBee object follow, although instead the flocking code has been quite altered.
For some reason I also had problems with the orientation of the bees, since they were all “spawned” twisted 90º in the Z axis. I fixed it by applying an extra rotation directly in the “flocks” script.
I also had problems making the agents collide with the insects, since they also bothered the LeadBee and the movement was, therefore, very orthopedic. I tried to solve it by making the bees collide with the police with colliders and not with NavMeshObstacles as I had originally done, but for this I had to use Unity layers and the result is not so satisfactory. Both options are included in the demo video.
Webography
- Simpson, C. (2023, December 8). Behavior trees for AI: How they work. https://www.gamedeveloper.com/programming/behavior-trees-for-ai-how-they-work
- Decision making for games . (n.d.). https://gebakx.github.io/dm-games/#38
- gameAIUnity/dm/dm.md at main · gebakx/gameAIUnity. (n.d.). https://github.com/gebakx/gameAIUnity/blob/main/dm/dm.md
- quick:design [BehaviorBricks] . (n.d.). https://bb.padaonegames.com/quick:design
- Stephen Barr. (2018, July 15). Unity AI Swarming Tutorial (Flocking but it follows the Player) [Video]. YouTube. https://www.youtube.com/watch?v=5ziHg2kO56s
- OpenAI. (2024). ChatGPT (Version 22 November) [Large language model]. https://chat.openai.com/chat
- ChatGPT chat used for implementation, troubleshooting compilation errors, providing ideas and cleaning up the code: https://chatgpt.com/share/67507a9f-7680-800b-9956-d8882661b1ed
Assets
Sketchfab. (n.d.). Beee, bumblebee – Download Free 3D model by i.deal3d. https://sketchfab.com/3d-models/beee-bumblebee-816b3d1876434439bb02b6046d51ca32
Sketchfab. (n.d.). Beee, bumblebee – Download Free 3D model by i.deal3d. https://sketchfab.com/3d-models/beehive-5627f41b490246a2a1e1e88b554e17bf
Sketchfab. (n.d.). Stylized tree stump – Download Free 3D model by Aartee. https://sketchfab.com/3d-models/stylized-tree-stump-04d51f5c2fb643aab3b93b451d1b77c9