This is an enemy AI behavior I made for an enemy that patrols around a level.
- At the start of the of the game this enemy will enter its patrolling state.
- In this state the enemy will move to the first way point in its list of way points.
- Once it reaches the first way point the enemy will then move to the next one in the list until it reaches its last way point in the list.
- When it reaches the last way point if the enemy has not been alerted by the player the enemy will turn around and move threw the list of way points in reverse.
- The enemy will enter this state when the player enters the enemies vision cone.
- The enemy will then check to see if it has a target. If the enemy lost vision of the target the enemy will go back into the patrol state and moving to the closest way point in the enemy’s list of way points and continue in its patrolling.
- If the enemy still has its target the enemy will charge at the target to get in the enemy’s attack range.
- The enemy will check after charging if it is in attack range. If the enemy isn’t in the attack range it will check to see if it has a target again.
- If the enemy is in attack range the enemy will attack the target.
- After attacking the enemy will check to see if it still has a target.
- If the enemy does not have a target the enemy will go back to its patrol state.
- If the enemy still has its target it will attack until it does not have a target.
Enemy Health System
- During all the other states the enemy will be checking to see if it has taken damage.
- If it has taken damage the enemy will subtract that much from it’s health pool.
- After subtracting from it’s health pool it will check to see if it still has health greater than 0.
- If the enemy’s health goes equal to or less than 0 the enemy will die.