AI Character as Enemy (part1)

AI Attack series (part5)


Create hitbox and actor tag:


Open Ninja BP, add Box collision in Component, name as HitBox (if player get in the box, ninja attacks and player healthbar reduces)
image.png
Set the hitbox position in Viewport
image.png
Select Mesh in compoent, change anim mode to Use Animation Asset
Aim to play to kick, untick looping and playing, adjust the intital position at the moment his kick at the peak point (should be around 0.7047)
image.png
Scale up and reposition the hitbox as follow, take different perspective (top and L/R) for reference:
image.png
image.png
Now can tick back play and looping on mesh

Go to Player BP, click on Player BP self in component, type tag in detail and rename them
image.png
Repeat the same in ninja BP (optional)

Create new task: DetectPlayerOverlap on hitbox:


Go to Behavior Tree, New Task, name as DetectPlayerOverlap
create variable and nodes as below:
image.png
Rename the character BP from Player1 to Player0

Back to behavor tree, create another task name as Attack
image.png

In Ninja BP, mesh, Change back anim mode to use animaiton bp
Go to Attack BP, Play montage node, change its play to kick montage
image.png

Go back to Behavoir tree, make a new sequence, add detectplayerovelap, and then new blackboard key attacking?
image.png
image.png

Add blackboard on attack node, set as below, and then copy and paste in Chaseplayer sequence, drag the blackboard on top,
image.png
key querry as not Set in chase player sequence blackboard
image.png
copy and paste on random roam sequence too, attacking as not set this time
image.png

Create Damage on player:

In Ninja AI folder, R click, create BP class, type animNotifyState, name as Ninja_ANS,
Open it, under +Add new tag, cursor move on Functions → click Override, choose Get Notify Name → then subchoose Notify Begin, and then subchoose Notify End (3 Eventgraphs are created)
image.png

In Get Notify Name, name Return value as follow:
image.png
Notify Begin (new type as query only):
image.png

Copy those middles nodes from NotifyBegin, paste in NotifyEnd, but plug Mesh Comp to Get Owner target, and set Collison Enable type to no collison
image.png

Open Ninja anim, kick montage, R click on the the row 1 under notify, select add notify state→ Ninja ANS
image.png
drag start and end dimaond from ninja kick starts and end (diamond box refers to hitbox being activated, i.e player only gets injury when he is in the hitbox during activated period of the kick)
image.png

Go to Ninja BP, duplicate a Hitbox, name as StartMelee? → Scale up the box size little bit more than the hitbox size (to let enemy detects if player is closed, then the hitbox size is to trigger attack)
image.png

Go to behavior tree → click Detectplayeroverlap node, change the hitbox node to StartMelee node:
image.png

Go to Ninja BP, hitbox, set its collision preset to custom, enabled no collision (i don’t need to do it, or else no damage worked), then click on component begin overlap
image.png
image.png

Go to player BP, add actor disable collison node at the end when player dies (i.e. ninja won’t have player box detected when he dies)
image.png


P.S. If set player death animation:

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.