AI Character as Enemy (part1)

AI chasing Player (part3)


Create enemy to sense player:


In Behavoir Tree → New Task → Click BTTaskBP, rename as FindPlayerLocation
Create Variable name as Vector (set as public), its type as Blackboard Key Selector
Connect variable and create nodes as follow:
image.png

Go to Behavoir Tree → Blackboard, add New Key, name as CanSeePlayer?, its type as Bool
image.png

Go to Ninja AI controller BP, Add AIPerception in Component
→ Details, add Array elements, change Index 0 and Dominant Sense to AISense Sight
image.png
Open up Sense and then Detection by Affiliation, tick all 3 detect Enemies, Neutrals, Friendlies (also check if starts Enabled ticked)
image.png

Let Player be sensed by enemy:


Go to Player BP, add AIPerceptionStimuliSoruce in component
In details →
tick auto register as soruce, and add array element, choose AISense sight
image.png

In Ninja AI Controller BP, AIPerception compoent, Details, click On Target Perception updated (bottom R corner), a relevant node is made in eventgraph
image.png

Rename the player BP as Player1_BP, complie and save all (for use and differentiate other player BP in event graph nodes creation)
Create nodes as follow in Ninja AI Controller BP
image.png

Go to Behavoir Tree, add a new sequence and add move to, findplayerlocation (make sure complie all BP)
image.png
In details, Set vectors of both nodes to Targetlocation
image.png
Selecct 1st sequence, R click → Add Decorator, Blackboard
image.png
Change its key to CanSeePlayer?, key Query to Is not Set (mean ninja cannot see player), Observer aborts to Both
image.png
Copy the Blackboard Based Conidtion node and past to 2nd sequence, but change pasted key Query to Is set (mean ninja can see player) instead
image.png
Add command (hit C after selected nodes) as follow:
image.png

Make enemy chase player more smooth:


To create a Chaseplayer BP class,
In behavoir tree, add task, rename as ChasePlayer
Add variable vector, set as blackboard.... publicize, create nodes as below:
image.png
back to the tree, replace (i.e. delete) Move to node in to Chastplayer node just created, change vector to targetlocation
image.png
R click on Chase player Sequence, add decorator → Cool Down
Set cool down time to 0.2sec
image.png

Go to ninja BP, character Movment component, search Rotation,
tick Use controller desired rotation, rotation rate Z from 500 to 270 (experiemnt it to see if ninja follow character differently)
image.png

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.