Recreating an L4D Witch, problems with cast damage to a BT Task.

I’m trying to create a system where the enemy character doesn’t do anything until you’ve annoyed it enough; like The Witch from Left 4 Dead. It’s proving quite a bit more difficult than I thought.

I have a single task at the top of the behavior tree. First there’s a dot product to make sure the enemy only receives damage when both the player and the enemy are facing each other. Next I have a line trace going from the player to the enemy, so that the enemy only receives damage when there is line of sight. Each line trace reduces a health variable, when it reaches zero, the BT Task is a success and the enemy character starts chasing the player.

However I’m having a few issues:

  1. I can’t call an Event Point Damage node in a BT Task, but I can call it in the Character BP. I originally tried to set this up just using the Character BP but I figured it might be too difficult so I set up an AI system instead. I have no idea how I’m going to set an Integer variable in the BT Task that can be altered by interactions from the player character; I’m not even sure if this is the right way to do things.

  2. I haven’t even started trying to implement audio cues from the player to the enemy. I have no idea how I would be able to do this in the same BT Task.

output
I changed a few things around a bit from the setup you described. Hopefully it makes it a bit easier!

I found it useful to break up the functionality:

  • PawnSensing Component - gives the witch the ability to see (and hear)
  • AIController Actor - processes the sight into info the behavior tree needs
  • BehaviorTree - just acts as the decision maker. All external info is sent into it through its blackboard, and it decides how long to wait, and when to chase.


First, add a PawnSensing Component to the AI’s controller. This will allow you to detect visual cues and sounds from within the controller blueprint. Here I’ve set the visual field to be 60 degrees, which is what that green cone represents.

image
Select the component, and in the details panel, press the + beside On See Pawn


In your controller, we’ll setup a function called “SetCanSee Player.” We’ll also use a Retriggerable Delay to set a timer to turn off seeing the player if the player leaves the vision cone.

image
In that function, we’re simply passing the information into the AI’s blackboard.


For the blackboard, I just use two variables - one that sets the player as a target, the other is the bool for CanSeePlayer.

image
The behavior tree is just two states set in a sequence, since once the witch starts chasing she never stops. We use the MoveTo node and put it in an infinite loop. (Also, MoveTo requires a NavMeshBoundsVolume stretched out over your geometry so the Witch knows how to move around the level properly)


The BTT_Observe task does most of the “witch” behavior work.

Instead of using damage, I created a float variable - patience - to represent how long she’ll wait. We use a blackboard key to read in whether the witch is seeing the player or not. If she sees the player, patience is decreased by delta seconds. Once it hits zero, the task runs “Finish Execute,” so that’ll it’ll move onto the infinite chase loop.


The logic for the player seeing the witch could be added in the AI controller, as well as giving the witch the ability to hear the player (through the PawnSensing component).

Here’s a great tutorial for using the PawnSensing component that helped a lot while I was building out the demo.

I hope this helps, and good luck!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.