Making the AI chase the player
There is a component named PawnSensing
that can be used to add vision and hearing to the enemy. We will use this component and expand our Behavior Tree to make the enemy pose some threat to the player.
Giving the enemy sight with PawnSensing
To grant the enemy the ability to detect the player, we need to add the PawnSensing
component to BP_EnemyController
and store the PlayerCharacter
reference in BB_EnemyBlackboard
when the enemy sees the player.
These are the steps to use the PawnSensing
component:
- Open the
BP_EnemyController
Blueprint. - Create a variable in the My Blueprint panel. In the Details panel, name the variable
PlayerKeyName
and change Variable Type to Name. Compile the Blueprint and set Default Value toPlayerCharacter
. - In the Components panel, click the Add button and search for
pawn
. Select the Pawn Sensing component:
- In the...