Skip to content

Teleport

Updated

Teleport (comp-teleport) lets the player point somewhere and jump there along an aiming arc. It is the most comfortable way to cross large spaces, especially in VR where smooth walking can cause motion sickness. It moves the entity it is on: a first-person camera, or the character a third-person camera follows.

  • Teleport only lands on surfaces marked for navigation. Read Navigation for NavMesh Walkable and NavMesh Collidable.
  • After a teleport, the camera’s controller takes over through Camera::relocate. See Camera director.
  • Its events reach scripts through a Signal Emitter on the same entity.
Prop Type Default Description
distance number 50 How far the desktop aim reaches, in horizontal metres.
slopeLimit number 45 Steepest surface it lands on, in degrees, 0 to 90.
color string '#38bdf8' The arc and landing ring colour while the landing is valid. Any CSS colour.

Only the Teleport the player looks through acts, so several in a scene never fire together:

  • On the rendering camera (first person), the camera lands at its eye height. With a Character Controller on the camera, its capsule moves.
  • On a camera that follows a target (Third Person or Orbit), or on that target itself, the target lands on its origin and the camera comes along, keeping its offset.
  • A Teleport on anything else does nothing until a camera looks through it.

On desktop, hold the right mouse button on the canvas to aim. The arc follows the pointer; release to land there. While the right button can teleport, the browser’s context menu is suppressed.

  • It lands exactly where the pointer’s ray hits a walkable surface, up to distance away.
  • Aimed at a wall, it lands on the walkable top up to 3 m above the hit, so you can reach a ledge by pointing at its face.
  • Past distance, or aimed at the sky, the arc turns red with no ring, and releasing does nothing.

In VR, the right controller’s grip aims the arc, launched along the controller. Releasing moves the player, and the XR rig follows. While the grip aims, the left stick belongs to the teleport, not to walking.

Teleport has no touch or gamepad control. On those devices, use spot points or a script.

With a Signal Emitter on the entity:

Event Constant Data When
Teleport::start EventType.Teleport.Start none An aim begins and the arc shows.
Teleport::aim EventType.Teleport.Aim { valid } The aim turns landable or blocked; first right after start.
Teleport::arrive EventType.Teleport.Arrive none The aim ended with a teleport.
Teleport::cancel EventType.Teleport.Cancel none The aim ended without one.
Teleport::end EventType.Teleport.End none After arrive or cancel.

The VR teleport sends the same events.

Teleport has no script method of its own: it is the player’s aiming tool. To move something from a script without aiming, use:

  • the Character Controller’s teleport(position, yaw?);
  • a rigid body’s teleport(position, rotation?);
  • a NavMesh Agent’s teleport(point);
  • a Spot Point’s travel().

You can still change its props at runtime with setProps, or switch it off with setEnabled(false).

TeleportLock.jx
#pragma lifecycle(startup)
function startup() {
const teleport = CameraDirector.main?.getComponent(TeleportComponent);
if (!teleport) return;
on('puzzle/start', () => teleport.setEnabled(false));
on('puzzle/solved', () => teleport.setEnabled(true));
}

Switching the component off stops aiming entirely; switching it back on restores it. Use this to keep the player in a room until a puzzle is solved, or during a cutscene.

2. Count teleports and change range with progress

Section titled “2. Count teleports and change range with progress”
TeleportRange.jx
#pragma lifecycle(startup)
let hops = 0;
function startup() {
const teleport = self.parent.getComponent(TeleportComponent);
teleport.setProps({ distance: 10, color: '#a3e635' });
on('player-cam', (event) => {
if (event.eventType !== EventType.Teleport.Arrive) return;
hops += 1;
if (hops === 5) {
teleport.setProps({ distance: 30 });
emit('hud/toast', { text: 'Teleport range increased!' });
}
});
}

The player starts with a short 10 m range and a green arc. After five successful teleports the script extends distance to 30 m. Only arrive counts; cancelled aims are ignored.

TeleportFeedback.jx
#pragma lifecycle(startup)
function startup() {
// The player camera has a Teleport and a Signal Emitter with the signal 'player-cam'.
on('player-cam', (event) => {
switch (event.eventType) {
case EventType.Teleport.Aim:
emit('hud/hint', { text: event.data.valid ? 'Release to teleport' : 'Cannot land there' });
break;
case EventType.Teleport.Arrive:
emit('sfx/whoosh');
Haptics.vibrate(40, { hand: 'right', intensity: 0.5 });
break;
case EventType.Teleport.End:
emit('hud/hint', { text: '' });
break;
}
});
}

aim arrives whenever the landing switches between valid and blocked, so the hint text always matches the arc colour. On arrive, the script plays a sound (through another script listening to sfx/whoosh) and gives a short buzz on the right controller in VR; on desktop Haptics.vibrate simply does nothing. end comes after both arrive and cancel, so it is the one place to clear the hint.

NoWalkZone.jx
#pragma lifecycle(startup)
function startup() {
// 'Lava Room' is a sensor box with a Signal Emitter 'lava-room'.
const character = CameraDirector.main?.getComponent(CharacterControllerComponent);
if (!character) return;
on('lava-room', (event) => {
if (event.eventType === EventType.PhysicsCollider.IntersectionEnter) character.setProps({ speed: 0 });
if (event.eventType === EventType.PhysicsCollider.IntersectionExit) character.setProps({ speed: 4 });
});
}

Inside the lava room the player cannot walk (speed 0) but can still teleport between the NavMesh Walkable stepping stones. The sensor box sends intersection-enter and -exit as the player’s capsule crosses it.

  • The arc is always red. The floor needs a NavMesh Walkable component, and must be no steeper than slopeLimit.
  • Nothing happens on right-click. Only the Teleport on the rendering camera, or on the target it follows, acts. Check where you put it.
  • Teleporting on a phone. There is no touch control; use spot points or a scripted teleport.
  • Looking for a teleport() method on the component. Use the Character Controller’s, rigid body’s or NavMesh Agent’s teleport.