x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

AI Chase if player too far

Hello all!

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.

Thank you!

Product Version: UE 4.17
Tags:
more ▼

asked Feb 07 '18 at 09:03 PM in Blueprint Scripting

avatar image

ernijsyoyo
3 1 3

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Feb 07 '18 at 09:45 PM

avatar image

Jin_VE
4.3k 31 77 40

avatar image ernijsyoyo Feb 08 '18 at 04:41 PM

Behaviour trees... okay.

I am currently using a blueprints with script as shown in the picture. that is basically how the character moves from target point to target point. I was thinking that what if I store first person player location as a float and constantly make the AI check if the player is within a range? If player is not in the range then chase and SpawnSoundAtLocation (to tell the player to follow AI) until player is within range, then continue on with journey.

Is my method inefficient? Should I redo the whole walking flow in a behaviour tree?

alt text

aimovementcode.png (112.4 kB)
avatar image ernijsyoyo Feb 08 '18 at 04:53 PM

This is the kind of logic that I was thinking would work, hence if the variable is true, the AI stops whatever is doing and starts a chase script.alt text

chaseflow.png (162.7 kB)
avatar image ThompsonN13 Feb 08 '18 at 05:10 PM

something like this should help to get you started. basically every one second the distance to the player is checked and if it is greater than 300 units the ai moves to the players location.

alt text

capture.png (160.0 kB)
avatar image Jin_VE Feb 08 '18 at 06:50 PM

Yeah, without a BT is even easier. Not sure why I didn't include that just in case. But you also don't want the AIMoveTo and this mechanism to fight each other. You should be to add your trigger-point following to the True pin of that branch. Added bonus is you won't be doing it on tick anymore which saves CPU. Just adjust the Time value of the SetTimer node so the AI is responsive enough but no more than that.

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question