Teleporting

Tutorial

·

Beginner

·

+10XP

·

30 mins

·

(175)

Unity Technologies

Teleporting

Let’s make a teleportation device, so that Ellen can teleport across the map. We’re going to make a space that Ellen can walk into which teleports them to another location elsewhere in the Scene.

Languages available:

1. Teleporting within a Scene

Let’s make a teleportation device, so that Ellen can teleport across the map. We’re going to make a space that Ellen can walk into which teleports them to another location elsewhere in the Scene.

To teleport Ellen within a Scene, you need to set up a transition. For this, we use the TransitionStart Prefab. This Prefab “sends” Ellen to the destination. It contains a Transition Point Component, which defines all the properties for where the teleportation starts, and where the teleportation should send Ellen.

First we need to set up the starting point of the transition:

In the Project window, go to Assets > 3DGamekitLite > Prefabs > SceneControl.

  • Find the TransitionStart Prefab.
  • Drag TransitionStart to the Scene view. Place it at a position where Ellen can walk into the Collider (the green wireframe box). In the example below, we’ve made a door frame and placed it inside that:

To set up the destination:

  • Drag another TransitionStart Prefab from the SceneControl folder into the Scene view, and place it inside the new exit door frame.
  • Rename it to TransitionEnd.

Now let’s link the two together:

  • In the Hierarchy window, select the TransitionStart GameObject.
  • In the Inspector window, find the Transition Point component.
  • Drag the Ellen GameObject from the Hierarchy window into the Transition Point component’s Transitioning Game Object field.
  • Set Transition Type to Same Scene.

On Trigger Enter means that the Transition only activates when Ellen enters the Collider and not on a key press. If you’d rather teleport only when the player press the interact key (E), set Transition When to Interact Pressed.

2. Teleporting to another Scene

Teleporting Ellen out of one Scene and into a different Scene requires a bit more set-up. To make Ellen transition to a new Scene, we need two Prefabs:

  • TransitionStart is the same Prefab you used in the previous section.
  • TransitionDestination is a Prefab that “receives” Ellen. It contains a Transition Destination component. Place this Prefab in a different Scene, where you want the transition to finish.

See the Component Reference Guide for full details of these two components.

Let’s set up the destination first, so that you have all the information you need later when you set up the start point.

Set up Transition Destination

To add a transition to a Scene, open the destination Scene, navigate to the Project window, and go to Prefabs > SceneControl. Drag TransitionDestination into your Scene, to the location you want the teleporter to lead to.

The TransitionDestinaton Prefab contains a Scene Transition Destination component:

First, set the Destination Tag to a letter. It doesn’t really matter which letter, as long as it is the only Scene Transition Destination component in this Scene with that letter.

Next, you need to tell it which GameObject it should expect to receive. Drag the Ellen GameObject from the Hierarchy window to the Transitioning Game Object slot.

Finally, make sure your destination Scene is in your Editor’s Build Settings. To do this, go to File > Build Settings and select Add Open Scenes.

Setting up TransitionStart

These settings are mostly the same as they were in the previous section, with a few changes:

  • Set Transition Type to Different Zone.
  • Set New Scene Name to the Scene you want to send it to.
  • Set Transition Destination Tag to the Destination Tag letter you set in the Transition Destination component.

Press Play and walk to where the transition is. You should travel to where you placed the TransitionDestinaton Prefab in the other Scene.

Complete this tutorial