Ive been trying to make a enemy AI that patrols the level and will swoop down and attack the player once it sees them. Is there a way to do this in Blueprint?
You’ll want to setup AI perception for seeing the player…beyond that…the patrolling can be done in behavior or the actor BP…I like behavior tree personallly …it’s essentially get random location in navigable radius…AI move to …but set the “z” to plus 500 or something…you’ll want to run a check in the behavior tree for having acquired a target …if true …use a BTT task to move to the player location and attack…the attack could be handled in the BT task though id recommend setting up and implementing GAS, and using a gameplay ability to control the attack … additionally GAS is great for handling health/mana/xp and about any other stats that need to be constantly monitored and used
Hey @Lily88777!
Check out this post of mine where I cover roaming on a floating pawn
When it comes to chasing and attacking the player, I wouldn’t recommend using a behavior tree if that’s all it’s gonna do. Building onto my blueprint code in the linked post, you can add a Branch
node after Event Tick right before the Add Movement Input
node that checks if the distance between the actor and the player pawn is less than a certain value, or you can also do a line trace to check if there are any obstructions, or check if the angle between the actor’s forward vector and the vector in between the actor and the player pawn is smaller than a certain value. And if the conditions you’ve determined are met, then redirect the execution flow from the already implemented roaming part to an upcoming chasing & attacking part using our Branch. In this new branch, once again use the Add Movement Input
node but this time the World Direction
pin is gonna be the player pawn’s location minus the actor’s location, normalized. And finally for attacking, you can either add a collision volume to your actor and check if it collides with the player pawn, or do a distance check right after our new Add Movement Input
node. Then if the conditions are met, damage the player pawn however you handle it.
Sorry for having to explain the second part with text but I tried to make it as clear as possible. Still, feel free to get back to us if you have any trouble implementing it!
Hope this helps!