How can I implement random character movement in the character blueprint?

I want to implement a system when at begin play the character chooses a random point (within the confines of the level) and moves to it. Once they reach this point they will choose another point and move to it and so on.
I currently have a Tick connected to an ‘Add movement input’ node that has it’s ‘World direction’ input set with a random unit vector.
The problem here is that the random unit vector is set every time the tick is activated, meaning the the character stands in one place and just jerks around.
Is there a way that I can activate the ‘Add movement input’ node with the tick but only have the world position reset once the character has reached its destination?
Also how would I go about confining the world position to be within a certain space?
Thanks in advance.

So first of all. Depending on what you want to do I would suggest using an AI controlled character.

It is a lot easier if you use the “Move To” command and a Behavior Tree as it automatically has this function. You create a task which finds the point where your unit should walk to and then simply call the “Move To” node.

But if you want to do this in this actor you could add a branch behind your current function, checking if your character is at the location and only changing the target (where he moves to) when he is.

To get a location within a certain space you could do a few things. There is a node called “Get float in range”. You can use this 2 or 3 times (depending if you just want a walking character (without the Z axis) or if you want a flying one) and make a vector. You can define the boundary for this variable so for starters you could just hardcode it.

You could also use two target points (Which you can set later in your level when you place the actor) and use those to define the boundary or use a second actor which is a volume with a function to get a random point within it and call this from your actor every time you need a new one.

Thanks for your response, I’ll have a go with the behaviour trees today.

The easiest way is to make an Aiconteroller BP with a “get random point in radius” set the base location (can be the characters current location) and radius “move to location” ( not the simple move to) set acceptance radius and place a nav mesh volume in the level. If you need I could make and post a BP later.

If you wish to do it the way you are, you could also get the random point and get your location and check vector length and feed that into a Boolean as to whether or not you can move.

create an Aicontroller class BP like this with a variable to store the NewDestination, then in your character BP defaults tab set Ai to use this BP.
then watch 'em run around.

Hi again ,

Just following on from this answer, is there a way that I could implement the random movement as you have outlined here, but stop and start it when an event takes place in the level or a key is pressed?
I need the characters to stop running when a mesh starts moving towards them but unfortunately I cant activate a custom event within the AI controller from my level blueprint, can you think of a workaround at all?

Thanks for you help.

I can not think of a reason why this should belong in the level bp but you totally should be able to.

Check out some tutorials on sharing variables and especially bp interfaces.

Simple See!

Add This Bool

then Cast to the Ai BP from any other BP And Switch The Bool On/Off.
Trigger it however you like

That’s it! Perfect thank you, I’ve been stuck on that for a while.
One more thing though if you don’t mind (and it is the last thing I promise!). How would I stop the character movement as soon as the event occurs as opposed to when they reach the target destination?
Thanks again for all your help.

no problem, glad to help. the stop movement node should stop the character immediately, it worked for me when i built it this morning. post your BS’s if it doesn’t ill take a look. let me know how you get on.
Cheers

Ah, I see where I’ve gone wrong now, sorted! Thanks very much.

Thanks for the node… i tried it too and it works…
only problem is that i dont know how to implement it inside behavior tree so i can set priorities below and above it… ??
basically to control when my AI character should move randomly or when it should not…???

check out peter newtons tutorials, very good in cases of ai