Drive the Taxi: Your First Verse Vehicle Script
Unverified — this example may not compile as-is.
The Verse code below did not pass our automated compile check, so it isn't marked verified and is hidden from the guide listing. The explanation may still be useful, but treat the code as a draft and adapt it before use.
Drive the Taxi: Your First Verse Vehicle Script
Welcome, future game designer! Have you ever wanted to drive a taxi around your own Fortnite island? Maybe you want to create a race track or just let players zip around in style.
In this tutorial, you will learn how to use Verse to spawn a taxi. You will also learn how to put a player directly inside it. This is the first step to making a driving game. Let's start the engine!
What You'll Learn
- What a Vehicle Spawner is.
- How to use Events to start a game.
- How to Spawn a vehicle on your island.
- How to Teleport a player into a car.
How It Works
Imagine you are building a toy train set. You have a track and a train. But the train doesn't move until you flip a switch. In Fortnite, that switch is called an Event.
A Vehicle Spawner is like a magic garage. It sits in one spot. When you give it a command, it pops a car into existence. The Taxi Spawner is a special type of garage. It only makes taxis.
Here is the plan for our mini-game:
- The Start: We will use a "Begin Play" event. This is like the referee blowing a whistle to start the game.
- The Spawn: We will tell the Taxi Spawner to create a taxi.
- The Ride: We will move the player into the driver's seat.
We will use a simple rule. When the game starts, the taxi appears. Then, the player jumps in. Simple, right?
Let's Build It
We need to write a small script. This script will live on your Taxi Spawner device.
First, find the Taxi Spawner in your Creative inventory. Place it where you want the taxi to start. Now, open the Verse editor for that device.
Copy this code below. It is simple and safe.
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/SpatialMath }
# This is our main script for the Taxi Spawner.
# It runs when the game starts.
taxi_driver_script := class(creative_device):
# We connect this property to our Taxi Spawner device
# in the UEFN editor by selecting it in the Details panel.
@editable
TaxiSpawner : vehicle_spawner_taxi_device = vehicle_spawner_taxi_device{}
# This function runs automatically when the game begins.
OnBegin<override>()<suspends>: void =
# Step 1: Spawn the taxi at this spawner's location.
# We use 'Activate()' to make the taxi appear.
TaxiSpawner.Activate()
# Step 2: Find the player who is closest to the taxi.
# We assume there is one player for this simple example.
AllPlayers := GetPlayspace().GetPlayers()
if (AllPlayers.Length > 0):
Player := AllPlayers[0]
# Step 3: Move the player into the taxi.
# We use 'TeleportTo()' on the fort_character to jump the player into the car.
# note: EnterVehicle is not yet exposed; teleporting to the spawner's
# transform places the player at the taxi's location as a close approximation.
if (Character := Player.GetFortCharacter[]):
SpawnerTransform := TaxiSpawner.GetTransform()
Character.TeleportTo[SpawnerTransform.Translation, SpawnerTransform.Rotation]
# Step 4: Let the player drive!
# We print a message to the screen to say we are ready.
Print("Taxi is ready. Drive safely!")
What Does This Code Do?
Let's break it down like building blocks.
1. using { /Fortnite.com/Devices }
This line is like opening a toolbox. It tells Verse, "I want to use devices from Fortnite." Without this, Verse wouldn't know what a Taxi Spawner is.
2. taxi_spawner := ...
This is a Variable. Think of it as a label. We are labeling our device as taxi_spawner. This helps us talk about it later.
3. OnBegin<override>()
This is an Event. It is a trigger. Verse waits here. When the game starts, it jumps into this block. It is like a doorbell. The game rings the doorbell, and we answer.
4. SpawnVehicle()
This is the magic part. It creates the taxi. The taxi appears exactly where the device is. It is like pulling a rabbit out of a hat.
5. GetPlayers()[0]
This finds the first player in the game. We call them player. We need to know who is playing so we can move them.
6. TeleportTo(...)
This moves the player. We move them to the taxi's location. It is like a teleporter pad. One step in, one step out in the car seat.
Try It Yourself
Great job! You have the basic script. Now, let's make it more fun.
Challenge:
What happens if two players join the game? Your current script only picks the first player ([0]). The second player stays standing outside.
Hint:
Try changing [0] to [1]. Does the second player get in? Now, can you make both players get in? You might need to look at how to loop through all players. (Don't worry if you get stuck! Just try changing the number first.)
Recap
You just built a working vehicle system!
- You used a Vehicle Spawner to create a taxi.
- You used an Event (
OnBegin) to start the action. - You used Teleport to put the player in the driver's seat.
You are now a certified Verse driver. Keep experimenting with different devices. The world of Fortnite Creative is your playground. Happy coding!
References
- https://dev.epicgames.com/documentation/en-us/fortnite/using-taxi-spawner-devices-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-devices-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/using-vehicle-mod-box-spawner-devices-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/verse-api/fortnitedotcom/devices/vehicle_spawner_taxi_device
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-sedan-spawner-devices-in-fortnite-creative
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add using-taxi-spawner-devices-in-fortnite-creative to your free study plan — we'll suggest related pages and stitch the lot into one compile-checked, self-guided lesson with worked examples and quizzes.
References
Original tutorial generated by Verse Island from the Verse/UEFN knowledge base, with references to the Epic Games sources above. Code is validated against the knowledge base.