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"

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.

Product Version: Not Selected
more ▼

asked Sep 12 '14 at 08:57 AM in Blueprint Scripting

avatar image

77 25 24 29

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

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.

more ▼

answered Sep 12 '14 at 11:08 AM

avatar image

5.9k 291 86 293

avatar image ThatJoeThom Sep 13 '14 at 12:08 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Sep 14 '14 at 01:52 AM

avatar image

Alan Webster
850 50 34 79

avatar image Alan Webster Sep 15 '14 at 02:06 PM

alt textcreate 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.

avatar image ThatJoeThom Oct 01 '14 at 07:33 AM

Hi again Alan,

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.

avatar image Erasio Oct 01 '14 at 08:47 AM

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.

avatar image Alan Webster Oct 01 '14 at 09:29 AM

Simple See!alt text Add This Bool

![alt text][2]

then Cast to the Ai BP from any other BP And Switch The Bool On/Off. Trigger it however you like [2]: /storage/temp/16713-can+move+switch.jpg

can move.jpg (76.0 kB)
can move switch.jpg (103.5 kB)
avatar image ThatJoeThom Oct 01 '14 at 10:16 AM

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.

avatar image Alan Webster Oct 01 '14 at 01:05 PM

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

avatar image ThatJoeThom Oct 01 '14 at 01:13 PM

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

avatar image VeerChidar Mar 24 '15 at 01:05 PM

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..???

avatar image makai Oct 26 '15 at 08:01 AM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Sep 15 '14 at 07:52 AM

avatar image

171 5 9 12

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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