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:
Go to Behavoir Tree → Blackboard, add New Key, name as CanSeePlayer?, its type as Bool
Go to Ninja AI controller BP, Add AIPerception in Component
→ Details, add Array elements, change Index 0 and Dominant Sense to AISense Sight
Open up Sense and then Detection by Affiliation, tick all 3 detect Enemies, Neutrals, Friendlies (also check if starts Enabled ticked)
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
In Ninja AI Controller BP, AIPerception compoent, Details, click On Target Perception updated (bottom R corner), a relevant node is made in eventgraph
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
Go to Behavoir Tree, add a new sequence and add move to, findplayerlocation (make sure complie all BP)
In details, Set vectors of both nodes to Targetlocation
Selecct 1st sequence, R click → Add Decorator, Blackboard
Change its key to CanSeePlayer?, key Query to Is not Set (mean ninja cannot see player), Observer aborts to Both
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
Add command (hit C after selected nodes) as follow:
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:
back to the tree, replace (i.e. delete) Move to node in to Chastplayer node just created, change vector to targetlocation
R click on Chase player Sequence, add decorator → Cool Down
Set cool down time to 0.2sec
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)