Anomalous Behaviour of an AI Animal - Subsumption and Steering Architecture
Project Name: Anomalous Behaviour of an AI Animal - Subsumption and Steering Architecture
Technology: Unity Engine, C# Scripting
Type: Solo Project
AI Behaviours Implemented: Seeking and Fleeing
Project Overview:
The project centers around 5 animals that are indicated by silver circles on the screen. Their actions are governed by subsumption architecture and steering behaviors. Their objective is to stay healthy and not be hungry. Each animal has 2 bars on its head. The yellow bar is the “hunger bar”. The green bar is the “health bar”. Food is denoted by Apples. Each animal will react to other animals around it.
AI Behaviour Description:
If the hunger bar has a value from 0 to 50, that means the animal is not hungry, and the animal will rest in its current position. If the hunger bar value goes above 50, then the animal will seek food. Eating/touching food takes the hunger bar back to 0. The green bar above the animal’s head denotes health. If the health of the animal is < 20% and it spots an animal nearby, it will flee to the nearest safe spot marked by caves. There are 4 caves around the map. Going back to a cave sets the cub’s health to 70, and then it will continue searching for food. If an animal finds another animal near food, then the animal will seek the other animal as it considers it a threat, instead of going for food. Touching animals deals random damage to both animals that are in contact. At 100% hunger, animals will start to slowly lose health.

Figure: Legend for the video above
Sensory System:
Each animal holds 3 lists in his memory. One list for the enemies, one list for food and one list for safe spots. Animals know each other’s location from the start, including food positions and the location of caves. These lists hold the X, Y world position of each entity. The lists are sorted every frame depending on the distance from other animals.
The distance between 2 entities is calculated using the simple vector line distance formula. The animal will always know the distance between the closest enemy and the closest food. These variables are also updated every frame.
Each animal entity holds 2 invisible circles around them. One is for “a minimum distance” another is for “a maximum distance”. The animal will ignore everything which is under minimum distance and which is outside maximum distance. Each food item holds an invisible circle around it too which will trigger 2 main subsumption functions.
Touching/Collision is handled by Unity’s collider system. Touching an apple is considered eating it, and touching another animal is considered doing damage to it.
Subsumption Architecture:
The basic function done by an animal is to rest/stay in one place. By default, each animal starts with 100 health and 0 hunger. That means it will be passive and will stay in one place until the hunger goes over 50. Hunger grows slowly over time throughout the game. Hunger going above 50 will force the animal to seek the food. However, hunger reaching 100 means the animal will lose his health slowly.

Figure: Subsumption Architecture
The base state of an animal is to “Target Food (Seek food)” which can be subsumed by 3 different functions. The food-seeking behavior is forced once the animal’s hunger bar value goes above 50. If the animal finds food and eats the food, then its hunger value goes to 0 and then the “Stay” function subsumes the food-seeking function. Once “Stay” comes into play, the animal will just stay in the same place until his hunger goes high again.
Food seeking can also be subsumed by the “Target Enemy (Seek Enemy)” function if the animal finds an enemy near the food area. Once the enemy is taken care of, then the “Target Food” function continues to run.
If the animal gets below 20% health, then the “Flee” function subsumes everything, forcing the animal to run to a safe spot. This “Flee” function has the top priority and cannot be subsumed by anything. Once the animal flees, it will go to the nearest safe spot, and then it will continue searching for food again.
All these decisions are followed by a “Path Plan” module, which does the number crunching of vectors and finding a path, which is then followed by the actual “Motor/Actuator” which physically moves our animal.
Steering Behaviors:
-
Seek:
Seeking is the most basic form of movement followed by animals in this world. Seeking is done by moving the animal object towards the target position. After each frame of the game, the target sets its “Forward” vector towards the target. Next, the animal object is moved in the direction of the “Forward” vector by the speed amount given by a default value. This movement happens each frame, resulting in the animal moving to the destination.
The pointing “Forward” vector towards the target happens every frame; thus this sometimes gives a feeling of “Pursuit” instead of just seek. We can consider this “Seek” as “Pursuit without prediction”. This can be seen clearly once there is only one Apple left on the map. If there is only 1 Apple left, then the player is provided with an option, whether or not to control the apple. The player can move the Apple using W, A, S, D keys, and all the animals will try to seek the apple together.
-
Flee:
If the animal wants to flee, then its forward movement is subsumed. I have actually implemented flee in 2 different ways. The default way was to move the animal in the opposite direction of the threatening animal. However, this sometimes made animals not find any food at all because if there are more animals than food, then the fleeing animal had no chance to regain health to 70% by eating food, as the animal was always fleeing from nearby animals around the food.