Skip to main content

ClimbingHand

A class in Root.Township, Features.Climbing.

One hand's climbing state: grabbing a climbable surface, holding the grip and working out how hard the hand pulls the body. Made per hand by ClimbingHandler; the grip is synced to other players.

Constructors​

MemberWhat it is
ClimbingHand(Controller controller, ClimbingHandler handler, PlayerUnlock unlock)Creates a ClimbingHand from controller, handler and unlock.

Fields​

31 private and internal fields
MemberWhat it is
private const int CheckFrameCountFrames a closed hand keeps trying to grab after a failed first try (5).
private int checkFramesFrames left to keep retrying a grab.
private IClimbable climbableThe climbable currently gripped.
private Collider colliderThe collider currently gripped.
private int currentlyGrabbingObjectLayerOriginal layer of the gripped object, synced to others.
private Vector3 currentPressureSmoothed pressure the hand is applying this frame.
private float currentPressureMagnitudeSize of currentPressure, exposed as CurrentForce while climbing.
private int frameIndexIndex into lastFrames.
private readonly MemoizeComponentOne<IClimbable> getColliderClimbableCached lookup of IClimbable on a collider.
private readonly MemoizeComponentOne<IClimbable> getRigidbodyClimbableCached lookup of IClimbable on a collider's rigidbody.
private readonly Vector3 grabPositionOffsetThe controller's grip point offset from the hand.
private static readonly Collider[] grabResultsShared buffer for overlap results.
private float gravityBoostHow much of gravity skips the pressure cap, set from the climbable and surface normal.
private RelativePoint? gripWhere the hand holds, relative to the gripped collider; null when not climbing.
private readonly ClimbingHandler handlerThe climbing handler that owns this hand.
private float incorrectHandStrengthModifierGrip strength from 0 to 1 that drops when the hand pulls wrongly; the grip breaks at 0.
private bool isHandClosedWhether the interact input is held.
private bool isHangingWhether the arm is at full stretch this frame.
private Vector3 lastArmDirectionDirection from shoulder to grip, from the last check.
private float lastArmLengthDistance from shoulder to grip, capped at the hang distance.
private int lastFrameProcessRanDeclared but not used.
private readonly Vector3[] lastFramesRecent hand positions used for pressure; holds one frame.
private readonly Transform masterHandRoot of the tracked hand.
private readonly Player playerThe network player who owns the hand, used to check sync permission.
private readonly Transform shoulderThe arm's shoulder (or the head if there is no arm IK).
private RelativePoint shoulderCacheShoulder position relative to the gripped collider from the last frame.
private static SphereCollider sphereShared sphere collider used for penetration tests.
private readonly MethodSync syncMethod sync for grip and release messages.
private readonly ThrottledMethodSync syncImmediateGrabFailThrottled sync for failed grabs.
private bool syncVoluntaryBreakWhether the last release was voluntary, sent with the release so others skip the break effect.
private readonly PlayerUnlock unlockUnlock required to climb, or null.

Properties​

MemberWhat it is
Vector3 ActualHandPosition { get; set; }Where the real (tracked) hand is while gripping, corrected for body velocity. Used for stamina drain by distance.
Controller Controller { get; }The hand's Controller.
float CurrentForce { get; }Size of the pressure this hand applied this frame. 0 when not climbing.
Vector3 CurrentGripPosition { get; }World position of the grip point. Zero when not climbing.
Quaternion CurrentGripRotation { get; }World rotation of the grip point. Identity when not climbing.
int CurrentlyGrabbingObjectLayer { get; }Physics layer of the object last grabbed. Picks the stamina use multiplier.
bool IsClimbing { get; }True while the hand holds a grip.
bool IsHanging { get; }True while climbing and the arm is stretched to the hang distance.
Vector3 LastArmDirection { get; }Direction from shoulder to grip at the last hang check.
Vector3 OldGripPosition { get; private set; }Grip world position from before this frame's update.
Quaternion OldGripRotation { get; private set; }Grip world rotation from before this frame's update.

Events​

MemberWhat it is
event Action startedClimbingRaised when the hand takes a grip.
event Action stoppedClimbingRaised when the hand lets go.

Methods​

MemberWhat it is
void BreakGrip(bool isVoluntary)Lets go: detaches the hand, plays the grab broken effect if not voluntary, syncs it and raises stoppedClimbing.
Vector3 HandPressure(float deltaTime, float gravity, ref float remainingPressure, out float pressureDirectionPower)Works out the push or pull this hand applies to the body from the hand's offset to the grip, limited by the pressure left.
bool Hang(Vector3 velocity, float deltaTime, float weight, out Vector3 shoulderPosition, out Vector3 neutralizeDirection, out float magnitude)Checks whether the body is hanging from this grip (arm stretched past the hang distance). Breaks the grip if the load is too great.
void Process(bool hasStamina)Per frame: grabs a climbable when interact is held with no interactable in reach and stamina left, or lets go.
void ResetPressure()Clears this hand's stored pressure.
Vector3 ResistPressure(Vector3 pressure, float pressureDirectionPower)Applies extra pressure to the gripped climbable and adds it to this hand's total. Returns zero if the climbable refuses it.
14 private and internal methods
MemberWhat it is
private void BreakGrip()Lets go: detaches the hand, plays the grab broken effect if not voluntary, syncs it and raises stoppedClimbing.
private bool CheckGrab(float armReduce = 0)Looks for a climbable surface near the hand within arm reach and grips it if found. Retries once with a shorter reach.
private bool CheckStreamReadPermission(IPlayer player, Stream stream)True when reading: on the server only from the owning player, always on clients.
private Vector3 EvaluateArmStrength(Vector3 pressure, float pressureDirectionPower)Scales a pressure by how closely it lines up with the arm direction.
private float EvaluateBestGrip(int overlap)Picks the overlapping climbable with the highest grip priority, falling back to the default climbable; returns that priority.
private Vector3 GetClosestPointToGrip(bool isRight, Quaternion handRotation, ref Vector3 handPosition)Finds the closest surface point to the palm, using penetration tests for terrain and concave meshes.
private void GetGrabAssistBlock(ref bool isBlocked)Blocks the interactor's grab assist while the player is climbing.
private bool IsReleasingCurrentClimbableImmediately()True when the current climbable can't be held and releases at once.
private void PlayReleaseImmediatelyEffects()Plays the grab-broken effect and syncs the failed grab to others.
private void ProcessTightGrip(RaycastHit hit, bool isRight, Quaternion handRotation)Attaches the hand to the hit point facing the surface, plays grab effects and syncs the new grip.
private void Serialize(IPlayer player, Stream stream)Syncs grip or release: climbable entity, position, rotation, layer and grip pose. The server only accepts it from the owner and relays it.
private void SerializePosition(Stream stream, ref Vector3 position)Syncs the grip position with the controller's chunk.
private bool ShouldBreakCurrentGrip(bool hasStamina)True when out of stamina or the climbable releases immediately.
private void SyncImmediateGrabFail(IPlayer player, Stream stream)Plays the grab-broken effect for others; the server relays it.

Used in​

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