This is the tree I’ve got:
The DetectEnemy Service should detect an enemy if the player is in reach and set the state appropriately to “scared” or “patrol” (if the player is not arround). When the bot is currently patroling and in the “Move To”-Task, it does not react, only when the bot reached the TargetPoint and the tree is traversed again from the top the state is changed. Maybe this is a bug since all of this is experimental or maybe I got the idea of the service and ticks all wrong. The interval for the DetectEnemy service is at its default 0.5.
Because you are executing move to task in Sequence so it will stay there until MoveTo is finished then after that it will go back to the root and check for new target again.
I recommend u in MoveTo node u can have a SimpleParallel, main will be MoveTo and the background stat u can put enemy checking there.
Thank you, I guess that’s a possibility. I tried something different and it worked for me.
First of all the service get’s called every tick and the state is changed appropriately but the blackboard decorator “patrol” doesn’t stop the execution of the subtree even if the state isn’t set to patrol anymore. It only prevents entering the subtree if the state isn’t set to “patrol”.
I fixed it by not using the “Move To” Task but creating a new task where I used the node AI Move To and also checked every tick if the state is still “patrol” (else finish execution without success). Don’t know if this is the most efficient way but it works for me
Normally i always have a selector with decorator for each different state, with decorator i set it’s to abort self, then inside selector i can have the sequence, task,… By set decorator to abort itself i can change state in blackboard anytime i want, and it just switch.
Thanks, that seems to be the correct way to solve this!