AI movement based on %

Hi,

I want to know how I could make an AI have movement opportunities based on %.
So for example: Every 5 seconds AI has 5% chance to move to a random target location.
How would this look in blueprints?

Thank you

Something along the lines of:

1 Like

Thats perfect! Thanks! I am having an issue with adding additional timers though. I want to have an order of events that happen at set times. I am trying to use unpause and pause timers but it doesnt seem to be working for me.
For example: AI will move between certain set random locations for 1 minute. Then after, AI will move to different set random locations for 1 minute. I need to pause the previous set locations when AI moves to the new set of locations.

Phase 1 and 2 was working but phase 3 was not, then after adding the unpause and pause timer handles for phase 3 stopped them all working for some reason

It’s all a bit strange. You’ve yet to enable Looping on the timer - so it can repeat, and instead of giving the AI an order to move, you shift its relative location. Relative to what?

I don’t want it to repeat though, I want each phase to only happen once for a set amount of time and then move on to the next phase (pausing the previous phase) which will be a completely different set of random locations for the AI to teleport around. I want the AI to be teleporting instead of moving, thats why I am having its relative location changed.

However I also would like the AI to return to a previous phase if the AI touches a certain object

Looping would allow you to do both - go through the location sets and pick up a random location from each set.

I want each phase to only happen once for a set amount of time and then move on

This would indicate that you do, indeed, want to repeat teleporting until time runs out. And the whole process will repeat for a new set of locations… I might be misunderstanding the big picture here, though.

Do we need to remember what happened in the previous phase?

Depending on the details, I wouldn’t bother with separate timers for each locations set (you can, but it could get fiddly and it will not be scalable at all in case you want to keep building on top of it), I’d do something like this instead:

None of the above has been tested on the battlefield.

Ah thank you! That really helps! Ticking the loop option actually fixed my problem! I’m now wondering whether I should use your blueprint or my original one. I still need the AI to move based on percentages and I prefered the way it was done in the first blueprint you showed me a month ago.
I’m just wondering how I can implement the return to a previous phase with the original blueprint. Lets say there are 4 phases: At phase 3 when the AI is touched by a certain object I need him to return to phase 2, if we are at phase 4 he needs to return to phase 3.
The object itself is an invisible cone and on button press the cone appears and dissapears, I have placed a sensor on the AI to detect said cone, but I am having trouble figuring out the command to use for the AI to react to said cone (I believe I need to use an ‘on hit’ bp but can’t figure out how to use it).
Following a guide I have set the correct collisions for said cone, it has the type of collision that only effects the AI and not the environment

It’s already included above. You call Restart Timer and feed it the Set ID of the required phase:

This would roll the phase back by 1. Just ensure you do not go below 0 or we’re gonna have a really bad time :wink: Arrays start at 0.


The object itself is an invisible cone and on button press the cone appears and dissapears, I have placed a sensor on the AI to detect said cone, but I am having trouble figuring out the command to use for the AI to react to said cone (I believe I need to use an ‘on hit’ bp but can’t figure out how to use it).

Use an overlap, as above. OnHit may not work all that well when teleporting and can produce multiple hits - pretty disastrous if we base any math on that - a DoOnce node could help. But proving the cone is not on the move, a Pawn detecting overlap will most likely suffice.

Ah okay! I’ll try it out. I’m guessing I will need to create multiple set ID’s for each phase?

Nah. SetID controls which phase we’re at:

It tells the pawn which array pull the locations from. Here we have 3 phases, each with a bunch of locations we access randomly at a time interval.

Oh very nice! That’s perfect. I guess the final question would be, how do I get a trigger volume(overlap?) to trigger on/off with button press?

You can emulate something happening by hooking it up to input:

This would trigger for both, an overlap & for a mouse button. Although it’s kind of fuzzy what is really needed here. Do elaborate if that’s not what is needed.

Sorry it’s a little complicated, basically I have trigger volumes for the player that depending where he is they trigger an on/off switch to work by pressing ‘E’, I want that on/off switch to also turn on/off the overlap for the AI to react to(go back 1 phase). and each on/off switch will create its own unique overlap at specific areas (which do the same thing(return AI back 1 phase))

In the middle of your blueprint is % with 3, what does that section of the bp mean exactly?

It’s modulo, it wraps a value back to 0 when it gets to 3. So you get a sequence 0,1,2,0,1,2,0,1,2…

So would that reset the phase sequence? I don’t want the AI to return to phase 1 unless ofcourse it gets touched by the overlap in phase 2.
After phase 4 I want the level to end

Yeah, it would reset it. Run a Branch and to something else: