AI attack only when attacked

Hi guys, i am a new user of UE4 and i am trying to figure out how can i make my AI bot to start attacking (punching) only when being attacked (punched) by my character. Here’s my behavior assets

As you can see i have set some tasks (BTT) for the bot and to be more specific here is the configuration of the two persumably assets that need to be adjusted in order to do the above mentioned:

BTT_botMovetoEnemy

and BTT_botAttackEnemy

All answers are appreciated. Thank you, in advance !

Hi,

Looks like you need some kind of a value (can be a bool) which gets set when the player punches the AI.
This bool can be directly linked to some value on the blackboard. Now in the behavior tree check for this value and start attacking the player (if the player is still in range).

Basically the high level steps would be :

  • In the AI blueprint check for overlap of the player weapon collider (attached to the hand for punches).
  • If an overlap is detected, set a value (maybe bool) in the blackboard of the AI.
  • In the behavior tree have a subtree which gets activated if the blackboard value is set.
  • The subtree should run the attack task where you can play the AI’s attack animation.
  • Also make sure the AI is in range of the player when you run the attack subtree otherwise the AI would just keep punching even when the player is further away.

This is just an overview of how u can probably do it.

regards,

Thanks for your response ! Indeed, i had already a boolean value to my main character BP for determining the punch montage to the respected button. So i just dragged this value and placed it in my bot enemy detection Service as a condition to a branch which allowed a triggered execution to my bot state > search and attack if true or patrol and ignore if false.