Kanda Players 0.7.0
Loading...
Searching...
No Matches
Teleportation

Teleportation in the Kanda SDK allows for instant repositioning of players, which is useful for respawning, level transitions, or gameplay mechanics.

Components

  • TeleportCommand: An RPC command sent by the server to request a player be teleported.
  • LocalTeleportEventData: An app event created by the client to request it be teleport.
  • TeleportFloor: Marks an entity's collider as a surface that can be a teleport target.
  • RequestSpawnPoint: A tag component added to player origin to signal that a spawn point teleportation should be applied.

OpenXr Components

  • RequestTeleportResolution: Used to state when to start the teleportation raycast. It also keeps the position and rotation where we need to teleport.
  • OpenXrTeleportArc: Used to hold the entities that represents source and target the arc ray cast.
  • OpenXrTeleportArcPoint: A dynamic buffer that keeps the arc points for visualization purpose.
  • OpenXrTeleportVisual: Holding the LineRenderer prefab as well as reference to the instantiated object.

Teleportation Process

  1. Initiating Teleportation:
    • Teleportation can be initiated by game logic on the server or by client request.
      • Servers create a TeleportCommand RPC targeting a player with the desired position and rotation.
      • Clients create a LocalTeleportEventData app event with the desired position and rotation.
  2. Sending Teleport Command:
    • The server sends a TeleportCommand RPC to the specific client.
  3. Client-side Handling:
    • The TeleportPlayerClientSystem on the client handles instances of TeleportCommand and LocalTeleportEventData.
    • It updates the local player origin's Movable component with the new position and rotation.
  4. Synchronization:
    • The local player's new position is then synchronized to the remote player representation through the normal synchronization process.

Teleport Floors

Entities with the TeleportFloor component are considered valid surfaces for teleportation. The CacheRespawnPointServerSystem uses these to determine valid positions for respawning.

OpenXr Teleportation

The teleportation in OpenXr can be done when the hands have RequestTeleportResolution, OpenXrTeleportArc, OpenXrTeleportArcPoint, and OpenXrTeleportArcVisual components.

In OpenXrTeleportClientSystem, the thumbstick input is checked and the teleportation ray is enabled when the thumbstick rotates to forward direction. When the ray hits the floor and thumbstick is released, LocalTeleportEventData is sent to itself so that TeleportPlayerClientSystem can do its work.

When teleportation ray is enabled, OpenXrTeleportVisualClientSystem instantiate the GameObject prefab from OpenXrTeleportVisual component that has OpenXrTeleportArcRenderer MonoBehaviour which is used to modify the line renderer to the correct arc shape and place the teleport target.

Respawning Example

  1. When a remote player is spawned (e.g., on joining a session):
    • The server adds the RequestSpawnPoint component to the player's remote origin entity.
  2. The SpawnPointServerSystem processes entities with RequestSpawnPoint:
    • It first tries to use a cached respawn point from the RespawnPoint buffer.
    • If no cache is available, it selects a random SpawnPoint in the world.
  3. The system then initiates the teleportation process as described above.
  4. After teleportation is complete, the RequestSpawnPoint component is disabled.

This system ensures that players are always spawned at valid locations, preferring their last known position but falling back to predetermined spawn points when necessary.