Modifying the Behavior of Agents

For our 2nd assignment in AI, we were too write a brief summary of each type of pathing behavior and how we would implement them into a game. We were to observe the agents that were provided to us by our Professor, which you will see in the images below.


Arrive 
When modifying the MaxForce by reducing it, it causes the object to pass through the point of arrival. Basically, when the object reaches it’s destination the MaxForce slows down the object to stop at it’s destination. When you reduce the force of MaxForce it stops the object at a slower rate, and when it’s increased it will force the object to stop quicker and exactly at the final destination point. Think of it as coming up to a street light. When the light turns red, you are forced to stop at a certain point. If the streetlight had a force, when it turned red, it would be at its MAX force. When you change the MaxSpeed, the object arrives at the final destination either faster or slower depending on the speed variable.
How I would implement this into a game? I would use this as a pathing agent for a variety of things. One idea would be for a game that I am making on the side. It’s a Diablo style of game, and one way to use the Arrive method would be an example of my “Click to Move” the player. Where ever you click on the screen, the player moves to that location at a certain speed.




Flee
Flee can be easily adjusted to generate a fleeing force only when an object comes within a certain range of the target. When the object reaches that range, it then slows down changes its direction and speed in the opposite direction of the target. How I would implement this into a game? I would this method into the my side project. Either for monster’s who are weak and tiny but are stronger as a group. If I stumbled upon them when one is alone, the enemy would flee back to it’s group. Another way of using this in a game would be a sort of aggro system.



Flocking
Flocking is also known as an emergent behavior. It a cluster behavior which can be best described as a flock of birds migrating. The birds all have the same destination, but will travel there by their own paths, maintaining a close nit formation. It can also be defined as separation, alignment, and cohesion.
How would I implement this into a game? This could be used for enemies in a game in order to keep a certain formation. It will help maintain a focus on one direction for the entire group of enemies, keeping them in the same direction, but by their own paths. When you look at the example EXE, by pressing “G” you can see that one “enemy” is the leader, and can attract the other enemies to follow him if they are in range.


Hiding
Hiding is an attempt to position an object behind an obstacle between the object and the object pursuing it. Given the position of the target and the position/radius of the object, we then calculate a position away from the pursuer from the object’s bounding radius and directly opposite the target. Once a position is determined, the “arrive” behaviour is used to steer the player to the closest position and if there is none, it will “evade”. How would I implement this into a game? This is a great way to have your NPC or enemies sneak up on a Player. Another example would be the Goblin from Diablo III. Once the Goblin see you, he run’s away until he doesn't see you anymore, then once he is at a safe distance, he will begin to set up his portal for a quick get away unless you can get to him to kill him first.


Interpose
This behavior returns a steering force that moves an object to the midpoint of another object’s path connecting them. It determines where the enemy object will be instead of merely following it. It must estimate where the agent’s path is going like “pursuit”.This behavior also uses the “arrive” behavior once the target has reached its position. How would I implement this into a game? This would be a great behavior to add to enemies who are in pursuit of you. Instead of just merely chasing you down, they can calculate your path, and cut you off where you going to be. Or maybe for a NPC or object to help you block a bullet being shot at you.


Non-Penetration Constraint
This behavior is the “flocking” behavior but without any penetration constraints. You have a main object that essentially gather’s up the herd instead of the herd following the object. How I would implement this into a game? This would be good to have during a RTS game, like Command and Conquer. If you have a big group of objects and you want to send them to a specific place, although they may take separate paths , they follow each other to that point. When you want to select a big group, you hold down the right click on the mouse to circle the group you want to control. 


Obstacle Avoidance
This behavior steer’s a object to avoid obstacles lying in it’s path. In order to achieve this, you would need to add some sort of detection collider around the object extending in front of it. The detection collider should be the same width as the object, and its length should be proportional to the object’s speed. The faster the object is going, the bigger the collider should be. How would I implement this into a game? Well for a NPC traveling through obstacles or a level, this would be needed in order to make sure that the NPC is not running into objects and getting stuck on them. If an object is in it’s way, with obstacle avoidance, it will determine that there is a object in it’s path, and be able to calculate an alternate path before it reaches the object. This could be good for racing games, shooting games, and more.


Offset Pursuit
This behavior will calculate the steering force required to keep an object positioned at a specified offset from a target. This is useful when you are trying to keep the objects in a particular formation. The offset is always the leader of the pack, and the other objects determine it’s path based off of the offset of the leader.  How would I implement this into a game? There a many situations that you could use this behavior, but to name a few, first would be for a sports game. This would be good for the NPC’s in the sports game in marking an opponent. Or in a space game, implementing some sort of battle formation for the NPC. Maybe you have a gang in Grand Theft Auto, with a leader, and everyone following behind him. Or maybe you are going to lead an army into battle. Usually you will say “CHARGE!” and everyone will then follow behind you as you charge forward.



Path following
This creates a steering force that moves an object along a series of waypoints forming a path. They usually have a starting point and ending point, but sometimes it’s a continuous loop. The simplest way to follow a path is to set the current waypoint to the first in the list, then once the object has reached it, or “seeked” it, grab the next waypoint in the list. You have to be careful when implementing pathing, as the behavior is very sensitive to the max steering force / max speed ratio. How would I implement  this into a game? This is the most commonly used steering force in games today. I would use this in my own game for my enemies that haven’t been spotted by the player yet. It’s a great way to set up your NPC’s to “patrol” their area. You could use this for FPS with guards patrolling an area they are protecting.



Pursuit
This behaviour is useful when you are requiring an object to intercept a moving target. You don’t want to just have the object run directly towards the moving object. You want to determine where the moving object is going and try cutting them off predicting where they are going to be. The success of the function depends on how well the pursuer can predict the evaders trajectory. This can get very difficult if not approached the right way, and you don’t want to obtain inadequate performance issues or eating up too many clock cycles. 
How would I implement this into a game? This would be good to use in a Space shooter game, such as Space Invaders. As the player is “flying” in a certain direction, the enemies are constantly trying to determine the player's path to either shoot it down, or run into the player to kill them. You can use this as well in a RPG game such as Diablo, for the enemies running after you when you are trying to “flee” from them.


Seek
This behavior return a force that directs an object to a target position. You calculate the desired velocity, as this is the velocity the object needs in order to reach it’s target position. This behavior is needed for a lot of the other steering behaviors.
How would I implement this into a game? Well in my side project, when I click on the map, my player then seeks out the desired location I chose and moves towards it at a certain velocity. This could also be used in a FPS for seeking missiles. Once you shoot the missile, it then detects the object it is trying to destroy and will actively seek them until it reaches it’s destination. 


Wander
Its designed to produce a steering force that will give the impression of a random walk through the environment the object is in. A great solution to this is to project a circle in front of the object and have the object steer toward that target that is constrained to move along the perimeter. A small displacement is added to this target and over time it moves back and fort h for a smooth wandering motion. How would I implement this into a game? This would be good for my NPC character in my game when they are sitting in their environment, waiting for action. Similar to pathing, but without waypoints. It will give the illusion that the NPC has a mind of it’s own, walking around the area it’s currently in. 


Big Shoal
This function checks to see if the first priority behavior is going to be evaluated in this step, depending on a preset probability. If it is and the result is non-zero, the method returns the calculated force and no other active behaviors are considered. If it is zero, the next priority is considered and so on and so forth. Depending on the Players reaction to a big group of enemies, will determine the enemies behavior.  How would I implement this into a game? This would be great for a game that involves a bunch of little enemies and one big enemy. Let’s say for instance a Shark game. I would be playing as the Shark, chasing down a big school of fish. The fish would maintain formation, and swim away from me depending on my reactions. If i choose to go straight at them, they would be able to detect it, and change their behavior to try and either “evade”, “flee”, or avoid me so they won't be eaten. 

Most Popular Blog Posts!