XRShared Locomotion
The XRShared addon provides several ways for a user to move: teleport and snap turn, with a controller beam or a finger beam, and "grab the world" locomotion.
All of them move the local hardware rig: it is the root of the tracking space, so the headset, hands and controllers move with it.
The locomotion itself is not networked: the local user network rig copies the hardware rig pose during FixedUpdateNetwork, and the other users see the move through it (see Rig Architecture).
Teleport and snap turn: RigLocomotion
RigLocomotion is placed next to the hardware rig component (an IMovableHardwareRig, like HardwareRig).
The default HardwareRig prefab (DefaultRigPrefabs/HardwareRig.prefab) already contains it, a Beamer prefab under each controller, and a Fader on the camera.
Snap turn
Pushing a controller joystick sideways (above rotationInputThreshold) rotates the rig by snapDegree around the headset.
debounceTime prevents several turns in a row while the joystick stays pushed, and disableLeftHandRotation / disableRightHandRotation keep a joystick for other uses.
Teleport
RigLocomotion teleports the rig when a teleport beam is released on a valid surface:
- the teleport beamers are the
teleportBeamerslist. When it is empty, theRayBeamercomponents under the rig are collected, including the ones created after the start (finger beamers added at runtime, ...), - a valid surface is a collider whose layer is in
locomotionLayerMask. The layer named inadditionnalCompatibleLayer(Locomotionby default) is added to the mask, if the project defines it. With an empty mask, an error is logged and all surfaces are accepted.ValidLocomotionSurfacecan be overridden for other rules.
The teleport beamers are also exposed as the rig "locomotion pointers" (ILocomotionPointersProvider): other systems can act on them without depending on the locomotion code. For instance, TogglePassthrough can hide them in passthrough mode.
Rigs not built from the default prefabs
For a hardware rig that does not contain the beamers or the fader, RigLocomotion can add them at start:
addBeamersToControllersadds thebeamerPrefab(the XRSharedBeamerprefab, found automatically in the editor) under each controller that has no beamer,addFaderToHeadsetadds aFaderto the headset.
Beams: RayBeamer
RayBeamer displays a ray (a line renderer) while its input is pressed, and raycasts along it:
rayActionis the input action enabling the ray. By default, any button on top of a controller: joystick click, primary or secondary button. A script driving the ray itself (finger beamer, desktop mouse, ...) setsuseRayActionInputto false and setsisRayEnableddirectly,origin,targetLayerMaskandmaxDistancedefine the raycast,hitColorandnoHitColorthe ray color,onHitEnter,onHitExitandonReleaseevents receive the hit collider and position.onReleaseis the one triggering a teleport,CancelHit()cancels the current hit: the next release does not triggeronRelease.
A beamer is also an interaction tip for UI interaction: when the scene contains an XSCInputModule, the ray stops on interactable UI, and on non interactable UI too while stopRayByNonInteractableUI is checked.
An IRayValidator (rayValidator field) is called on each hit, and can change the beamer status (for instance, to refuse a target).
To show a user's ray to the other users, use a RayPointer instead (Interactions/Beamer/Prefabs/RayPointer.prefab): a RayBeamer which is also a hardware rig part, synchronized by a NetworkRayPointer on the network rig.
Finger beam: FingerBeamer
FingerBeamer controls a beamer with hand tracking, so that a user without controllers can teleport:
- forming an "L" shape with the thumb and index, with the other fingers closed, enables the beam,
- lowering the thumb while the index still points releases it, and triggers the teleport,
- any other change (hand opened, index closed, hand not tracked) cancels the beam, to prevent an unexpected teleport.
It is placed on a HardwareHand providing the finger poses (typically the XRHandsHardwareHand of the XRHands synchronization rig parts), and drives the RayBeamer found in its parents or children.
Hand tracking jitter is amplified by the beam length, so several settings stabilize the beam:
smoothAim: the beam origin and direction are smoothed with One Euro filters (directionFilter,originFilter),activeBeamAngleMarginandactiveBeamDistanceMargin: while the beam is active, the pose thresholds are wider, so that a pose near a threshold does not end the beam,releaseConfirmationDuration: the thumb has to stay lowered this long before the release,releaseRewindDuration: lowering the thumb also moves the wrist, so the teleport targets where the beam pointed this long before the thumb started to drop.
poseDurationBeforeBeamActivation and cooldownBeforeBeamReactivation delay the beam activation, after the pose is formed and after the previous beam.
FingerBeamerSetup, placed next to the hardware rig component, adds a RayBeamer (the beamerPrefab) and a FingerBeamer to each HardwareHand of the rig, including the hands created after the start.
It is useful for rigs not built with XRShared, like Meta building block rigs (see the Meta Core integration addon). Hands that already have a FingerBeamer are kept as is.
Grabbing the world: SelfLocomotionGrabbable
With "grab the world" locomotion, the user grabs an anchor and pulls it: the rig moves instead of the object, as if the user was pulling themselves through the scene.
SelfLocomotionGrabbable is a Grabbable whose grab moves the local hardware rig. It is local only: it should not have a NetworkGrabbable (an error is logged otherwise), and each user has their own anchor.
Each frame, the rig moves so that the anchor stays where the hand holds it:
rotationConstraintType: withRotationFilter, the world turns with the hand yaw (rotationConstraintkeeps or ignores each axis of the hand rotation). WithLookAtHeadset, the hand rotation is ignored, and the anchor keeps facing the headset,positionConstraint: the hand moves along a world axis set to 0 are ignored. For instance,(1, 0, 1)prevents vertical moves,applyGrabberOffset: the world turns around the grab point (the pinch point for hands, the grabber for controllers) instead of the anchor center,amplifyBasedOnMoveSpeed: fast hand moves move the rig further than the hand (moveSpeedAmplificationCurve, hand speed measured overspeedEstimationDuration), to cover long distances with short gestures,maxMoveSpeedandmaxRotationSpeedlimit the rig moves. AmaxRotationSpeedof 0 disables the world rotation.
The rig is assumed upright: the constraints use world axes.
The InstantWorldLocomotion prefab (Interactions/HardwareBasedGrabbing/Prefabs/Locomotion) contains an anchor, displayed by a DisplayWorldLocomotionAnchor. The anchor appears in front of the headset (spawnPositionOffsetRelativeToHeadset), and again after each release, while one of these triggers is on:
forceDisplay, switched byToggleForceDisplay()(for instance from a menu): the way to use it with hands,displayOnButtonPress: while one of thedisplayButtonsof a controller is pressed. The user grabs the anchor while holding the button.
Fading during moves
A sudden move of the view can be uncomfortable. When RigLocomotion teleports or turns the rig, it asks the rig for a "snap movement visual protection": the HardwareRig darkens the view, moves, waits a short time, and clears the view again.
While the movement is in progress, SnapMovementInProgress is true, and RigLocomotion waits for its end before another snap turn (a teleport can start during it).
The fade is done by the Fader of the headset (an ICameraFader), which displays a colored overlay in front of the camera:
fadeColor, and the default durationsblinkDurationIn,blinkDurationSpentInandblinkDurationOut,FadeIn(the overlay appears: the view gets dark) andFadeOut(the overlay disappears) coroutines,Blink(both), theirAnimateFadeIn/AnimateFadeOutversions, andSetFade(level)can be used for other needs (loading, ...).
The fader uses the Unlit/Fader shader. To include it in builds, add it to the "Always Included Shaders", or add the FaderShaderCollection to the "Preloaded Shaders", in the project Graphics settings: the Fader logs a warning in the editor when neither is done.
Alternatively, the FaderViewMaterial preset uses the faderViewMaterial (by default, the URP URPUnlitSimpleFader material), which is also compatible with passthrough.
ConnectionFadeManager, placed under the NetworkRunner, keeps the view dark until the local user has joined the Fusion session, then clears it.
Custom locomotion and locomotion listeners
Moving the rig
IMovableHardwareRig, implemented by HardwareRig, is the API used by the locomotion systems:
Teleport(position, addSnapMovementVisualProtection): moves the rig so that the headset ground projection reachesposition,Rotate(angle, addSnapMovementVisualProtection): rotates the rig around the headset,SnapMovementInProgress: true while a faded move is in progress.
The desktop rig uses the same API (DesktopController keyboard moves and rotations, without fading).
Locomotion listeners
Some systems need to know when the user moves: for instance, colocalization breaks as soon as the user moves away from the shared real room.
A hardware rig implementing ILocomotionNotifyingHardwareRig (like HardwareRig) warns its IRigLocomotionListener listeners right before each locomotion, with its kind: Teleport, Rotation, or WorldMove (called on each frame of a world grabbing move).
C#
public class LocomotionLogger : MonoBehaviour, IRigLocomotionListener
{
ILocomotionNotifyingHardwareRig _hardwareRig;
private void Update()
{
// The hardware rig may change (rig selection, ...)
var hardwareRig = HardwareRigsRegistry.GetHardwareRig() as ILocomotionNotifyingHardwareRig;
if (hardwareRig != _hardwareRig)
{
_hardwareRig?.UnregisterLocomotionListener(this);
_hardwareRig = hardwareRig;
_hardwareRig?.RegisterLocomotionListener(this);
}
}
private void OnDisable()
{
_hardwareRig?.UnregisterLocomotionListener(this);
_hardwareRig = null;
}
public void OnBeforeRigLocomotion(IHardwareRig rig, RigLocomotionKind kind)
{
Debug.Log($"Locomotion: {kind}");
}
}
The Anchors addon LeaveIRLRoomOnLocomotion uses it to leave the colocalized room when the user moves.
The HardwareRig Teleport and Rotate methods already notify the listeners.
A custom locomotion system moving the rig transform directly should call rig.NotifyBeforeLocomotion(kind) right before the move, as SelfLocomotionGrabbable does.
Systems moving the rig for other reasons than a user locomotion (colocalization, ...) should not call it.
Locomotion validation
A component implementing ILocomotionValidationHandler, placed on the RigLocomotion game object or one of its parents, can refuse a teleport: CanMoveHeadset receives the headset position after the move.
The Locomotion Validation addon uses it to block forbidden zones and restricted areas.
Last updated on
Back to top