Enemy Movement
Enemy Movement

Enemy Movement

Enemy Movement

Enemies have two types of movement:

  1. Simple – a linear movement, where it goes in a straight line to the target
  2. Complex – a Path* algorithm that allows the enemy to dodge the environment and other enemies

The overall behavior is dictated by the enemy’s Enemy Logic – AI. Within each tree, a series of task nodes define the movement.

Each node can encapsulate an entire state, or a group of nodes could define that state. I have found that having a single node (

The movements vary and switch to be optimized. If an enemy is looking straight at the player it uses a simple linear movement, that consists of:

  1. Cast a ray toward the player, if there are no obstacles or walls, move in that direction
  2. If there are obstacles, but the player is in sight, change to complex movement and run a path* algorithm to go around the obstacle

This function calls Raycast in the intended direction and sets the flags and values accordingly.

One new flag we added was isHittingDoor which allows us to know if the enemy is attempting to bypass a closed door. This will trigger different behavior for enemies in pursuit, allowing them to attack the door or return to patrol.

Obstacles are usually tagged with collision and are meant to stop enemies and projectiles from passing through. Walls serve a similar purpose but are classified separately. Most enemies use a local avoidance system to overcome obstacles or other enemy instances.

The movement grid adapts with its surroundings (such as closing doors) and forces the AI to a specific room. It also was made to work in tandem to the original 16×16 pixel grid that makes the environemnt beneath it.