Random distribution of devices.

I’m looking for a way where I could distribute a number of devices be distributed randomly between certain positions.

What I have though of is having an invisible prop represent the pre established positions in game (Position 1 through 5) and having them shuffled in an array to randomly determine where to move the device to on game start.
Is this possible?

This is absolutely possible!

I would create a tag in your verse script and mark the objects with the tag. If you don’t want the objects to be shown in your game, you can simply disable it in the settings (Actor Hidden in Game).

Thereafter, we just need to select a random part from the list of parts that we marked with the tag (in this case I marked 5 random props). Then, we just need to copy the translation (position / location) of the selected prop to our device. I got this working with this script:

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Verse.org/Simulation/Tags }
using { /Verse.org/Random }
using { /UnrealEngine.com/Temporary/SpatialMath }

locations := class(tag){}

main := class(creative_device):
    @editable MyVeryFancyDevice : trigger_device = trigger_device { }

    OnBegin<override>()<suspends>:void=
        LocationParts := GetCreativeObjectsWithTag(locations{});

        if (RandomPart := LocationParts[GetRandomInt(0, LocationParts.Length - 1)]):
            Transform := RandomPart.GetTransform();

            # in case you also want the rotation of the
            # other part, use Transform.Rotation
            if (MyVeryFancyDevice.TeleportTo[Transform.Translation, IdentityRotation()]) { }

Hopefully that answers your question :slight_smile:

1 Like

Appreciate it. Works great, but what if I also wanted more devices, so like MyVeryFancyDevice2, MyVeryFancyDevice3 …
which would also be distributed randomly between the 5 locations? thanks

Well, it would be the exact same logic, but you would have to iterate over a list of devices (unless you have a fixed amount, and you think simply using @editables would be easier).

Try researching for loops, that should give you a better understanding of the case :slight_smile:

1 Like