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