# Spawn A Vehicle With a Keycard and Speed Boost

**URL:** <https://forums.unrealengine.com/t/spawn-a-vehicle-with-a-keycard-and-speed-boost/2229613>\
**Category:** Verse\
**Tags:** unreal-engine\
**Created:** [December 18, 2024, 2:21am UTC](https://forums.unrealengine.com/t/spawn-a-vehicle-with-a-keycard-and-speed-boost/2229613 "2024-12-18T02:21:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris4573](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@chris4573](https://forums.unrealengine.com/u/chris4573)\
**Post date:** [December 18, 2024, 2:21am UTC](https://forums.unrealengine.com/t/spawn-a-vehicle-with-a-keycard-and-speed-boost/2229613/1 "2024-12-18T02:21:38Z")

</div>

Hello, I’m here to share my code for a vehicle spawner. This spawner allows you to use a conditional button to check if they holding a card then spawn a vehicle. I also added a special bit where a movement modulator will spawn under the card once spawned!

![CarSpawnerExample](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/b/7/9b72d6c762c9b28b115372c6d84717a8b258da4f.gif)

Initially I wanted to create some simulator but didn’t get the chance so have fun!

```auto
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Fortnite.com/Characters }
using { /UnrealEngine.com/Temporary/SpatialMath }

CarSpawnerHandler := class(creative_device):

    @editable var SportsCarSpawner : vehicle_spawner_sports_car_device = vehicle_spawner_sports_car_device{}
    @editable var SportsCarButton : conditional_button_device = conditional_button_device{}

    @editable var MovementModulator : movement_modulator_device = movement_modulator_device{}

    var WasHoldingCard :int = 0

    AgentEntersVehicle(Agent:agent):void=
        ApplySpeedBoost(Agent)
         
    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        SportsCarSpawner.AgentEntersVehicleEvent.Subscribe(AgentEntersVehicle)

        spawn{CarSpawnersLoop()}

    CarSpawnersLoop()<suspends>:void=
        loop:
            Sleep(1.0)

            AllPlayers := GetPlayspace().GetPlayers()
            for (Player : AllPlayers):
                CheckForCard(SportsCarButton, SportsCarSpawner, Player)
       

    CheckForCard(CardDetector:conditional_button_device, CarSpawner:vehicle_spawner_device, Agent:agent)<suspends>:void=

        if:       
            CardDetector.IsHoldingItem[Agent]
        then:
            if:
                FortCharacter := Agent.GetFortCharacter[]
                FCTransform:=FortCharacter.GetTransform()
                WasHoldingCard <> 1
            then:
                DespawnAllVehicle()

                Print("Car Spawned")
                CarSpawner.RespawnVehicle()

                if (CarSpawner.TeleportTo[FCTransform.Translation, FCTransform.Rotation]):
                    Print("Car Teleported")

                    set WasHoldingCard = 1
                    Sleep(1.0)
        else:
            set WasHoldingCard = 0

    DespawnAllVehicle():void=
        SportsCarSpawner.DestroyVehicle()
        Print("All Cars Destroyed")

    ApplySpeedBoost(Agent:agent):void=
        if:       
            FortCharacter := Agent.GetFortCharacter[]
            FCTransform:=FortCharacter.GetTransform()
        then:
            if (MovementModulator.TeleportTo[FCTransform.Translation, FCTransform.Rotation]):
                Print("Speed Boost Applied")  

SpeedBoostManager := class(creative_device):

    @editable var SpeedBoost : movement_modulator_device = movement_modulator_device{}

    OnActivationEvent(Agent:agent):void=
        OriginPosition:= vector3{X:=0.0, Y:=0.0, Z:=0.0}

        if (SpeedBoost.TeleportTo[OriginPosition, IdentityRotation()]):
            Print("Returning Back To Origin")
            
    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        SpeedBoost.ActivationEvent.Subscribe(OnActivationEvent)

```
