AI Chase if player too far
I've realized that I am lacking some basic knowledge. I've made a script for AI to follow trigger points throughout the map, but how would one go about at making an AI chase player if he is too far from AI? As soon as AI is close enough to the player then the AI would have to continue on walking through the trigger points.
I am making an audio game intended for blind people and the AI is essentially like a guide. Looking after the player and making sure he doesn't get lost in the map.
If you're using a behavior tree then it's pretty straight forward. You just need to create a new descriptor that tests (distance-to-player >= max-distance). Then add a selector node instead of your existing pathing logic. Add a MoveTo node under the selector and give it the descriptor you made. Then add to the selector your logic that follows the trigger-points (you're kind of inserting the selector to provide a decision point).
So now if the descriptor passes (returns true), it will trigger the MoveTo (near player location) but if it returns false, it will trigger your pathing logic. If you want the MoveTo to interrupt the pathing at any time then you can select the descriptor in the MoveTo and in the details panel, change "Observer Aborts" to "Lower Priority". Otherwise, he will go all the way to the next trigger-point before he realizes the player is out of range.
Hope that was clear enough. If you are unfamiliar with behavior trees (descriptors and such) then we can find you a good tutorial video. You're also welcome to post an image of your existing behavior tree and we can find the right spot for the selector and its sub-nodes.
answered Feb 07 '18 at 09:45 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here