Skip to main content

TelescopicPickup

A class in Root.Township, the global namespace.

A pickup that extends or shortens along an axis as the player pulls their two hands apart, like a spyglass. The length is worked out on the holder's side in the IK update.

Constructors​

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

Fields​

14 private and internal fields
MemberWhat it is
private Vector3 axisLocal direction the moving part slides along.
private CenterOfMassSetter centerOfMassCentre of mass setter averaged between the hands while held.
private PlayerCharacter characterThe player holding it with both hands, while they do.
private float currentLengthCurrent distance of the moving part along axis.
private GrabPoint grabLeftGrab point held by the left hand.
private GrabPoint grabRightGrab point held by the right hand.
private float lengthOffsetDifference between the length and the hand distance when the second hand grabbed.
private float maximumLengthLongest length.
private float minimumLengthShortest length.
private float moveSpeedFastest the length can change, per second.
private Transform movingPartThe part that slides in and out.
private FloatEvent progressSetEvent fired with the new progress whenever it changes.
private float syncPrecisionPrecision used when syncing progress.
private MethodSync syncProgressMessage carrying the progress.

Properties​

MemberWhat it is
Pickup Pickup { get; }This entity's main pickup.
float Progress { get; private set; }How far extended it is, 0 at minimumLength to 1 at maximumLength.

Methods​

MemberWhat it is
override void Initialize()Creates the progress sync message.
override void OnConnected(Player player)Sends the current progress to a player who connects.
5 private and internal methods
MemberWhat it is
private void Awake()Reads the starting length and progress, hooks grab and release, and disables updates.
private void IkUpdated()Before each IK update, sets the length from the distance between the hands (clamped and speed-limited), moves the hand anchors and reports the new Progress.
private void InteractionEnded(Interactable interactable, Interactor interactor)Clears the released hand's grab point and stops the IK hook.
private void InteractionStarted(Pickup interactable, Interactor interactor)Records which grab point each hand took; once both hands hold different points, hooks the holder's IK update and stores the length offset.
private void Sync(IPlayer player, Stream stream)Serializes Progress; a client applies it to the moving part. As decompiled it uses InverseLerp for the length, so remote lengths are probably off.