Stop AI from chasing player

So I have a cow in a pen I made for him. I am using 2x and 2y values to keep him patrolling in a square when roaming. When he gets the signal to attack he will chase the player and deal damage. I am using a simple “AI move to”, as I find that pawn sensing is quite inaccurate in my experience. However I would like for the cow to stop chasing me when he leaves the cow pen. (it is currently a gap, which will have a door later. But in case it is open, I still want the cow not to go trough.) I tried this with a few Booleans and tick events, but I cannot get it to work. I mainly use a invisible wall as a trigger to get this to work, but no luck yet.

EDIT:
The main problem is that the attack event is not called again until he hits me once. If someone has an idea on how to stop this event prematurely, that would give me enough info to fix it.

Here is my setup of the cow blueprint (brown human currently xD) and my world:

If you are developing a single player game you can use a tick driven way to check if the cow is still in his pen (cow locationX is between X limits of the pen AND same for Y) and the tick it leave the pen you change the state and call the reset.

A more “correct” approach is to use a trigger box who trigger your cow reset event like in the attached picture:

this should work (change the state before reset, lol, forgot about it)

Well, the reset Ai event really only checks what state it is currently in, so without changing that value it won’t change anything. And I actually did try this, but the main problem is that is stays in it’s attack event once triggered until I am dead, regardless of resetting the AI since it ignores other custom events if it is still running one. It will top that event when he reaches me and then calls the event again if I am not yet dead. How can I successfully break that event without letting him reach me first?

Ops, I don’t know how I didn’t notice it lol, is actually pretty simple.

Looking at the execution flow of AttackPlayer Event we can notice that after the cow land an attack it check if the player is still alive, if he is, the cow will recklessness attack the player, again, and again, and again until the player die. In the branch who check the Player HP you should add an AND who:

  • check the state of the cow

or

  • the cow is in the pen

in this way if the cow isn’t allowed to attack it will return to roam.

Yep. Tried that before as well. The problem remains: This will only be checked if the AI move to was a success. And it will also be called only after each time the cow reached the player, and never inbetween. but I am currently looking into the stop on overlap part of the ai move to and see if I can do some magic with that :slight_smile:

Instead of edit your current branch you can add an other branch at the beginning of the event who check the state and call the roam event if not allowed to attack. Also doing this you can call your attacking event in case of AIMoveTo fail (it fail, so attack again checking if it can or not).

EDIT: BTW if you don’t check the state, with this BP, you are in a infinite loop broken only by the player’s death.

So this is my current blueprint. Once the cow hits the trigger it send a (succesfull) signal to the cow blueprint and switching the variable of ‘out of pen’ to on. This triggers a tick event to keep spamming attack thus getting fail results to break the current attack. This SHOULD happen in my theory, but it just keeps attacking me.

EDIT:
I fixed it. Turns out the event tick was so fast, it was just glitching. After adding a delay node right after where I turn ‘out of pen’ to off, it worked. I probably didn;t make the smoothest solution, but it will do for now :stuck_out_tongue: . Thank you for all your help :smiley: