Kanda Players 0.7.0
|
Teleportation in the Kanda SDK allows for instant repositioning of players, which is useful for respawning, level transitions, or gameplay mechanics.
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.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.TeleportCommand
RPC targeting a player with the desired position and rotation.LocalTeleportEventData
app event with the desired position and rotation.TeleportCommand
RPC to the specific client.TeleportPlayerClientSystem
on the client handles instances of TeleportCommand
and LocalTeleportEventData
.Movable
component with the new position and rotation.Entities with the TeleportFloor
component are considered valid surfaces for teleportation. The CacheRespawnPointServerSystem
uses these to determine valid positions for respawning.
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.
RequestSpawnPoint
component to the player's remote origin entity.SpawnPointServerSystem
processes entities with RequestSpawnPoint
:RespawnPoint
buffer.SpawnPoint
in the world.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.