Choose random player location?

How do I pick a random character’s location in a game from an array? The game would have up to 4 characters with some being bots.

thank you.

From the screenshot it looks like you are making a new array every time a player or AI overlaps the trigger. You want to create the array somewhere else, like OnBeginPlay and add a new vector to the array OnBeginOverlap. Once you have an array populated with multiple vectors (test it by printing the elements to the screen), then you can get a random index.

You can simply use the Random Integer in Range and have Min as 0 and max as the array length.

Hope this helps!

Thanks CoquiGames, now I just need to find a way to hook the random in range to set new location.

Hi [MENTION=24813]Joker of all trades[/MENTION],

Check out my graph for the way I would do it:


Notice how on Overlap Im adding a new element to the array. Make sure your trigger is set to collide with the right things (Pawns, etc) and ignore the rest (like dynamic objects).

Once the location is added, Im getting a random integer between 0 and array length - 0 and using the resulting integer to select an array index. Then Im setting the trigger location to this new location.

Notice I used the trigger at the end (like your graph). If you want to set the Player location, make sure you use the Player’s reference and NOT the trigger.

Hope this helps!

Thank you, thank you, thank you.

It works. Before I was trying to cast to player and ai then to get actor location which was not working. I thought I always had to cast to player to get their location.

So the bigger picture is getting the game to detect all the players’ and bots’ material and take a random one and put in onto a lift. Everything seems to work … in a way. With the randomizer above it either takes takes the last actor’s material that touches the box. If more than one actor is in the box, the lift turns to the default material.

Here are triggers 2 and 3:

I think what will fix this is replace event begin overlap for trigger 1 with when the lift is spawned in get player locations.

A mega thanks!

Yes I did it. I need to make a new variable from the in the variables panel, disconnect the appends and the get node to hook it up. Thanks a lot. Like a billion times. :smiley:


Glad I could help :slight_smile: