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"

How do I move an actor to a series of target positions randomly?

Hi folks, I was hoping for a bit of advice to do something which I think is simple enough to do, but I don't have alot of experience using Blueprints.

What I'd like to do is to have an array of positions (a few target nodes would be fine) and move a specified actor to one of the nodes at random. Also I'd like to be able to stay in that position for a random amount of time (with a specified min and max time) before moving again to a different random target.

Can anyone offer an advice on how to do this please?

Many thanks,

Paul

Product Version: UE 4.16
Tags:
more ▼

asked Nov 30 '17 at 01:36 PM in Blueprint Scripting

avatar image

Bushey
54 3 7 14

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

3 answers: sort voted first

Make timer

https://docs.unrealengine.com/latest/INT/Gameplay/HowTo/UseTimers/Blueprints/

on each timer event pick random item from array and do with it whatever you need, when actor reaches the point use Delay or Timer to set timer again so new position is randomized.

more ▼

answered Nov 30 '17 at 09:45 PM

avatar image

Shadowriver
36.6k 932 169 1111

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

They are stored in an array, so I'd use a random range starting with 0 for minimum, and the length of the array -1. You can then fetch a random index to get a random position. You can then use MoveTo if the actor is an AI. If the actor isn't an AI, you will need to get your controller to navigate to that position (which is more difficult). Once it moves, use a random range again to get a float for the wait time (the range you want) and feed it into your delay node. After the delay node, call your movement function again.

Another option is using a blueprint Timer with a random time (since you can't use a delay node within a function).

more ▼

answered Nov 30 '17 at 09:48 PM

avatar image

Nice_Rain
249 13 14 30

avatar image Bushey Nov 30 '17 at 10:49 PM

Thanks for the advice, I understand it in principal but can't visualise it in BP -

I've made an array of target points that I'd like my actor to go to but I can't get further than that.

avatar image Bushey Nov 30 '17 at 10:50 PM

I can't get it to loop around - I don't know where to plug the completed node into

alt text

avatar image Nice_Rain Nov 30 '17 at 11:05 PM

Starting with your loop, place all of those nodes into a function. You can name your something like RandomMove. When you press your button, call that function. After your setactorlocation node, add a SetTimerByFunctionHandle to call the function you created (Random move). You can set this timer to whatever delay you would like (by getting a random range)

avatar image Nice_Rain Nov 30 '17 at 11:07 PM

You don't need the loop, you can fetch directly from the array using your random integer and feeding it into the Get node.

avatar image Nice_Rain Nov 30 '17 at 11:08 PM

Your random integer in range needs to have the min 0 and the max is the length of the array -1

avatar image Bushey Nov 30 '17 at 11:29 PM

So here's my Function alt text

avatar image Bushey Nov 30 '17 at 11:30 PM

And here's my Event Graph - but it only does this once and the sphere dosen't make more than one move. alt text

avatar image Bushey Nov 30 '17 at 11:12 PM

Am I barking up the wrong tree?

avatar image Nice_Rain Dec 01 '17 at 12:10 AM

The function below includes the random move function within it. It uses an array of positions to move the actor to a new location (defaulting to the actor that this function is in). It also randomly sets a timer and calls RandomMove again after a set amount of time. In your even graph, connect this function to your 'pressed.' Once you press your key, the function starts, and it will automatically keep looping.

alt text

avatar image Bushey Dec 04 '17 at 08:59 PM

Hello, thanks for the BP diagram. How did you make the GET from set actor location to Random integer in range and the array?

avatar image Nice_Rain Dec 04 '17 at 09:17 PM

Just click and drag the array peg off then type "get"

avatar image Bushey Dec 04 '17 at 09:21 PM

Thankyou, such a silly question I know. I've got lots to learn :)

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

Adjust to your needs https://i.imgur.com/WOAsOwT.png

more ▼

answered Dec 04 '17 at 09:30 PM

avatar image

Nachtmahr
7k 143 28 172

avatar image Bushey Dec 04 '17 at 10:02 PM

Works like a charm! Thanks so much Nachtmahr!

(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