Skip to main content

ClimbingHandler

A class in Root.Township, Features.Climbing.

Runs climbing for one player's smooth locomotion: tracks both hands' grips and stamina, moves and turns the body as the hands move, and holds the body up against gravity.

Constructors​

MemberWhat it is
ClimbingHandler(SmoothLocomotion smoothLocomotion, PlayerUnlock unlock)Creates a ClimbingHandler from smoothLocomotion and unlock.

Fields​

10 private and internal fields
MemberWhat it is
private readonly LocomotionController coreLocomotionThe player's locomotion controller.
private readonly Transform headThe player's head transform.
private RelativePoint headCacheLateUpdateHead position from the last late update, used to pin the head while climbing.
private readonly ClimbingPressureCalculator leftHandPressureCalculatorPressure maths for the left hand.
private float minMoveDistanceCacheCharacter controller min move distance saved while climbing (set to 0).
private const string PlayerWeightStatNameName of the stat added to the base weight (playerweight).
private readonly ClimbingPressureCalculator rightHandPressureCalculatorPressure maths for the right hand.
private float stateChangeTimeWhen climbing last started or stopped, used for Friction.
private readonly PlayerUnlockManager unlockManagerThe player's unlock manager, which can override the climb layer mask.
private readonly Stat weightStatThe player's weight stat, added to the base weight.

Properties​

MemberWhat it is
float BodyHeight { get; private set; }The current body height. Moves toward the climbing height while climbing and back to normal after.
float Friction { get; }Ground friction from the settings' fade curve, low just after letting go and rising over time.
bool IsClimbing { get; }True while either hand is holding a climbable surface.
LayerMask LayerMask { get; }Layers that can be climbed. A current unlock that overrides climbing replaces the settings' mask.
ClimbingHand LeftHand { get; }Climbing state for the left hand.
IHandStaminaManager LeftStamina { get; }Stamina for the left hand. A fake one that never runs out when the character has no health.
ClimbingHand RightHand { get; }Climbing state for the right hand.
IHandStaminaManager RightStamina { get; }Stamina for the right hand. A fake one that never runs out when the character has no health.
ClimbingSettings Settings { get; set; }The climbing settings, ClimbingSettings.Instance by default.
SmoothLocomotion SmoothLocomotion { get; }The locomotion this handler moves.

Methods​

MemberWhat it is
void LateUpdate()While climbing, moves the body so the head stays where it was relative to the grip.
void Process()Runs one frame of climbing: updates hands, body height, movement, hand pressure and stamina.
7 private and internal methods
MemberWhat it is
private void AdjustHeight(float deltaTime)Moves the body height towards climbing height or standing height.
private void HandleClimbing(float deltaTime)Moves the player with the grips, applies hand pressure and keeps the player treated as grounded.
private void HandleHandPressure(float deltaTime)Works out pressure from both hands against gravity and weight, then sets the new velocity through Hang.
private void HandleSurfaceMovement()Moves and turns the player to follow how the grip points have moved since last frame.
private void Hang(float deltaTime, float weight, Vector3 velocity)Limits velocity so arms don't stretch past hang distance, using the more stretched hand.
private void Rotate(float degrees, Vector3 oldCenter, Vector3 newCenter)Turns the player around the old grip centre and moves them to the new one.
private void UpdateHeightBasedOnCollision()After climbing, sets the body height from a sphere cast down so the player doesn't clip into the floor.

Used in​

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