top of page
  • Adel Talhouk

Stealth Game Enemy

Inspired by a direction my capstone team considered taking our game and my lack of experience with Epic's Unreal Engine, I decided to try and implement an enemy that would patrol an area and chase you if you are detected - behaviours found in a typical stealth-based game. To achieve my goal, I used Unreal Engine's Behaviour Tree and Blueprint scripting to define the enemy's behaviour and transition from one branch of the tree to another.




Let me start with an overview of the tree. We have a selector node that tries to execute two main behaviours - ChasePlayer and Patrol, and a Wait Task Node in case the others fail.



The ChasePlayer Sequence has a Decorator attached to it that checks if a bool, bHasLineOfSight, is set in the Blackboard. This bool gets set set or

cleared in the Blackboard through the Enemy Controller Blueprint. It checks if a stimulus is sensed (from the On Target Perception Updated node) and that the actor sensed has the "Player" tag. If the bool is set (true), then it also sets a value in the Blackboard to reference the actor sensed, in order to move to their location - with the help of the Nav Mesh. The Behaviour Tree Task to chase the player simply updates the movement speed, as the enemy controller takes care of the logic to detect and keep track of the player, and the Rotate and Move To nodes take care of the pathfinding and movement. If the line of sight is broken (stimulus returns false), then it starts a timer, at the end of which the enemy

actor finally clears the references it has to the player actor and the bool used in the sequence node's decorator. This effectively makes the enemy seem more intelligent to the player, giving the impression that it followed them to the last location it saw the player at. At the end of the timer, when the bool gets set to false, the tree returns out of the branch, since the condition is no longer satisfied.


The Patrol sequence uses another custom Behaviour Tree Task to find a random patrol point on the map, then moves to it (again using

the Nav Mesh) and waits for 4 +- 1 seconds. The BTT_FindRandomPatrol task simply updates the walk speed, gets a random reachable point in a specified radius around the enemy actor, and sets it as the target patrol destination in the Blackboard. If the GetRandomReachablePointInRadius node fails (returns false), the it sets the patrol location to the enemy actor's location.


And that's it! With these two simple behaviours and a little setup in the Enemy Controller, we have a very basic stealth game enemy character. Granted, the enemy has no way of damaging you or calling for assistance, but this is the very basic framework to build on.


References:

23 views0 comments
bottom of page