Verse Library verse

01 Device

Full device class linking a trigger and mover to auto-toggle a door on player entry and exit.

verse-library/verse-if-else-branching-to-make-decisions-in-your-game/01-device.verse

# This script makes a door open when a player enters a trigger.

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

# This is our main device.
# It connects to the Prop Mover and the Trigger.
smart_door_device := class(creative_device):
    # These are the parts we will control.
    # We will set these in the editor later.
    @editable
    door_mover : prop_mover_device = prop_mover_device{}

    @editable
    player_trigger : trigger_device = trigger_device{}

    # We track whether the door is already open so we
    # do not try to open it again while a player is inside.
    var DoorIsOpen : logic = false

    # This function runs once when the game starts.
    OnBegin<override>()<suspends> : void =
        # Subscribe to the trigger's events.
        # AgentEntersEvent fires when a player walks in.
        # AgentExitsEvent fires when a player walks out.
        player_trigger.AgentEntersEvent.Subscribe(OnPlayerEnter)
        player_trigger.AgentExitsEvent.Subscribe(OnPlayerExit)

    # Called automatically when a player enters the trigger.

Sign in free to read the full source 🌴

This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.

Sign in with Discord

Comments

    Sign in to vote, comment, or suggest an edit. Sign in