Hive Assault: Swarm Intelligences



The Aliens in Hive Assault
A description of the methods behind the ants and the aliens
Dale Webster, 2001. Email: dwebster@rice.edu

When Hive Assault was first conceived way back at the beginning of the semester, the Alien race was going to be the focus of the game, with several types of aliens with radically different behaviors and appearances. The "worker" aliens would act as a colony of ants would; gathering food and running from place to place using pheremone trails. The "soldier" aliens would be created using evolution of skeletal animations, and would be human controllable. The Queen alien herself would be human playable, and would have limited control over the movement of all the aliens in the hive.

Well, as the AI team diminished in numbers from 3 to 1, the target complexity of the aliens decreased as well. The final goal was to have a single class of aliens which would be found spread out through the level, and would tend to run away from humans until they found reinforcements. We wanted to have a large concentration of these aliens in and around the Queen's chamber, and we wanted them to look good in groups and move and attack in interesting ways. By trimming our goals down to this manageable size, we were able to implement a cool alien with interesting behaviors that is actually pretty fun to fight against.

The final individual alien can move either the same speed as a human, or a bit faster. It is about half the size of a human, and has a single melee attack which it generally uses by jumping at a human. The aliens tend to run from humans if they are in groups of 3-5, but will attack viciously if they are in a larger group. They try and avoid walking "inside" each other, but in some instances they still do. Doing alien-to-alien collisions in Hive Assault was basically out of the question, as we need all of the computational resources we can get. Aliens originally spawn in random positions in the Voxel Volume, but will quickly move to the chambers in the Hive so they do not spawn outside of the geometry. Once they are killed, they immedialtely respawn inside the queens chamber. This results in a frenzied melee in the Queen's chamber which adds some challenge to a team of rocket-weilding marines.

The internal representations of the Aliens come in 2 flavors. When aliens are "uninstantiated", they are called "Ants", and are not rendered and do not follow the geometry for movement. These Ants would be easily modifiable to make them do interesting things like food gathering, etc. But for right now, they simply move to their designated waypoints (random chambers within the hive, or the Queens Chamber), and wait until a human or humans approach. If an Ant changes into an Alien, then back into an Ant, it simply stays where it was when it "deinstantiated".

The second flavor is the "Alien". This is an instantiated Ant, which is rendered and uses physics to move about the hive. When an Ant comes within a defined distance of a Human Player, it will tell the CreatureClient (controls all the Ants on a machine) to instantiate itself. The Creature Client will then remove the Ant from the Linked List of Ants, and add it to the Linked List of Aliens as a new AlienEntity. The CreatureClient takes care of shuffling Ants and Aliens back and forth, and ticks each of them. When an AlienEntity is built, the CreatureClient then calls "registerLocalEntity" on the Alien, which tells the networking and renderer to deal with this new Entity.

It is quite possible that the Alien is spawned in mid air, so the first thing that the Alien does it suck itself to the nearest wall by casting 27 rays and looking for intersections. From now on, the Alien maintains Up, right, and forward vectors used for movement and animation.

High Level Alien Movements
At the high level, the Aliens have a few basic behaviors. They keep track of how many fellow aliens are nearby, and based on this number they either move away from, or towards the nearest Human Player. Once they get within jumping distance of a Human, they jump at it. If they hit the human, then they cause 8 damage. After they hit, they have a reload time for both the jump and the attack, and so they run away from the human until this time is up. The nice thing is that they havea method "moveTowards(location)". This, combined with a "jumpTowards", is the basis of most of the high level actions for the alien. The Alien will also get stuck at times, when the normals it records are zero. In this case the Alien will usually jump towards whatever it is following at the time, and in rare cases where it ends up in free space, it will use the same "suck" function as above to suck it to the nearest wall. When many aliens move together using these rules, the small amounts of randomness I add to the movement, and the desire aliens have to maintain a minimum distance from each other, make for interesting circular movement patterns. It also makes for great fun when you move within jumping distance of a large group of them; you usually get hit by a LOT of flying aliens.

Low Level Alien Movements
At the low level, Alien movement was HARD. It took forever to get the Aliens to move towards a goal along the geometry. The main problem here was that we wanted the aliens to defy gravity ONLY while they were attached to a surface. The problem comes when an Alien goes over an edge, and all of a sudden has nothing under them. The final solution for this was to do an expensive series of ray casts to suck the Alien back down. The other problem was the question of how to get the Alien to move parallel to the surface it is on, but in the general direction of the goal. For this we used a method somewhat analogous to the HillClimbing method in search problems. We actually allow the Aliens to move away from the goal, but only when it is necessary. We do this by making their final vector of movement a weighted average of the vector parallel to the surface and the vector to the goal. The vector towards the goal was fairly simple to calculate, but getting the parallel to the wall vector was a bit more difficult. After much painful thinking, we came up with a good method. The vector is calculated by taking the left vector of the Alien (negative of the right vector) and crossing it with the normal of the surface the Alien is currently attached to. Using these methods in tandem we were able to make the aliens move in an amazingly realistic fashion towards a goal. Implementing JumpTowards(goal) was not quite as difficult, basically we launch the Alien in a direction which is a weighted average of the goal vector and the normal vector of the current surface. We then apply our own set of physics to the Alien as it is "jumping", and once it hits a new surface we start over with the original physics. This results in an Alien that can jump from the floor to the ceiling and start walking there, a very cool looking effect. I also keep track of the Alien's forward vector while in the air, so the animation has been said to look like a jumping dolphin. (another cool effect) The attack of the Alien is very simple, the Alien can automatically hit you if it gets close enough. (a stright distance check), but it does have a reload time. Basically one Alien is dodgeable if you concentrate on it, but any more than that and you will start getting hit.

These are the basic workings of the Aliens. They are very expensive to calculate in large numbers, we estimate we could calculate physics and decisions for approximately 200-300 aliens on a single machine where the only other major load is networking of the bugs. (and still run at ~30fps)