Skip to main content

PlayerLocomotionController

A class in Root.Township, the global namespace.

The VR body's LocomotionController: adds teleport styles (instant, lerp, fade), combat steps and smoothing of remote bodies. Get it from PlayerCharacter.LocomotionController.

Constructors​

MemberWhat it is
PlayerLocomotionController()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

19 private and internal fields
MemberWhat it is
private Coroutine currentTranslateRunning LerpPosition coroutine, stopped when a new teleport starts.
private LayerMask dashBlockageMaskLayers that block a combat step.
private float dashCooldownSeconds between combat steps. Defaults to 0.5.
private LayerMask dashStandableMaskLayers a combat step can land on.
private int halfStepsHow many times a blocked step is retried at half the distance.
private bool isUsingTrailWhether moves show a teleport trail. Set from the remote trail sync.
private float lerpDurationDuration of the combat step move. Zero uses the default teleport duration.
private static readonly Logger loggerNLog logger for this class.
private float maximumFallHow far down a combat step looks for ground.
private float maxStepAngleSteepest surface, in degrees, a combat step can land on.
private Transform originTransform whose rotation turns stick input into a step direction (the player camera).
private static readonly AccumulativeAverageCount prepareForWriteTimerStatic backing field for the explicit PrepareForWriteTimer.
private MethodSyncStruct<bool> remoteTrailMovementMethod sync on EffectRequest for the trail flag.
private static readonly AccumulativeAverageCount serializeTimerStatic backing field for the explicit SerializeTimer.
private PlayerLocomotionController.SmoothingSetting[] smoothingSettingsLocomotion and transform lerp pairs, one per PlayerSmoothManager setting index.
private NetworkTransform[] smoothTransformsNetwork transforms whose lerp is set by the smoothing setting.
private float stepVelocityDistance of a full combat step. Defaults to 0.6.
private LocomotionStyle styleTeleport style used for combat steps. Defaults to Lerp.
private Vector3 translateVelocitySmooth-damp velocity used by LerpPosition.

Properties​

MemberWhat it is
Vector3 BodyPosition { get; set; }Where the body target was when a trail teleport started.
bool IsOnCooldown { get; set; }True while a combat step is cooling down.
protected PlayerCharacter PlayerController { get; }The body as a PlayerCharacter.
2 private and internal properties
MemberWhat it is
private AccumulativeAverageCount Alta.Networking.INetworkSerialized.PrepareForWriteTimer { get; }Shared timing stats for preparing player locomotion writes.
private AccumulativeAverageCount Alta.Networking.INetworkSerialized.SerializeTimer { get; }Shared timing stats for serializing player locomotion.

Methods​

MemberWhat it is
override void Initialize()Sets up the trail message and applies the player smoothing setting.
override void MoveTo(Vector3 position, LocomotionFunction function)Moves the feet to a position. On the owner it teleports; on any other side it sends the move to the owning player.
override void RotateAroundPlayer(Quaternion rotation, LocomotionStyle teleportStyle, float duration)Turns the body while keeping the player's real feet in place.
void TeleportTo(Vector3 position, TeleportMode mode, LocomotionFunction function, bool isUsingTrail = false)Moves the body with a style and duration. Fade goes to black and back; lerp smooths there first. Can show a trail to others.
void TeleportTo(Vector3 position, TeleportMode mode, LocomotionStyle style, LocomotionFunction function, float duration = 0.02, bool isUsingTrail = false)Moves the body with a style and duration. Fade goes to black and back; lerp smooths there first. Can show a trail to others.
void TryStep(PlayerInput controller)Combat step: tries a short hop in the stick direction onto standable ground, then starts the cooldown.
protected override void InternalFaceTowardsXZ(Vector3 forward)Rotates the body around the player so the head faces a flat direction.
protected override void OnEnable()Hooks the teleport arrive sound on clients.
9 private and internal methods
MemberWhat it is
private IEnumerator LerpPosition(Vector3 target, float duration, Action lerpFinishedCallback) (iterator)Coroutine that smooth-damps the local position to a target, then runs a callback. Used by Lerp-style teleports.
private IEnumerator LerpRotation(Quaternion rotation, float duration) (iterator)Coroutine that slerps the rotation to a target. Not called in this class.
private void OnDestroy()Unhooks from PlayerSmoothManager.SettingChanged.
private void OnDisable()Client: unhooks the teleport arrival sound.
private void RemoteTrailMovement(IPlayer player, Stream stream, bool isUsingTrail)Method sync for whether the last move used a teleport trail. The server relays it to everyone else.
private IEnumerator RunStepCoolDown() (iterator)Waits dashCooldown, then steps again if a Step action is still held, otherwise clears IsOnCooldown.
private bool SetupOrigin()Editor helper: sets origin to the player camera.
private void TeleportFinishedSound(PlayerController player, Vector3 oldPosition, Vector3 newPosition, LocomotionFunction function)Client: plays the teleport arrive sound after a teleport-locomotion move.
private void UpdateSmoothing(int smoothingLevel)Applies the smoothing setting at the chosen index to the locomotion lerp and the smoothed network transforms.

Used in​

Members of other types that take, return or hold a PlayerLocomotionController: