Skip to main content

RopeGrab

A class in Root.Township, the global namespace.

A grab handle on a rope belt (rope pulls, lifts): pulling the handle turns the belt, and the belt's turn is tracked as progress 0 to 1 along the rope's length. Progress is saved and synced from the server.

Constructors​

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

Fields​

25 private and internal fields
MemberWhat it is
private float currentProgressBacking field for Progress.
private Interactor interactorInteractor holding the handle, or null.
private float interactYHandle's height along the rope, clamped to yMinimum and yMaximum.
private bool isGrabClampedIf true, the hand point is pushed back when progress hits an end.
private bool isInfiniteIf true, progress isn't clamped at all.
private bool isLoopingIf true, progress isn't clamped; there is no wrap-around code.
private bool isSyncingTrue while blending to the server's progress.
private float lastBeltRotationBelt rotation last frame, used to measure movement.
private float lengthRope length in metres that maps to progress 0 to 1. Saved.
private float lerpSpeedSpeed of the blend to synced progress.
private float maximumForceLargest torque the hand can put on the belt.
private float maximumForceDistanceHand movement per frame that gives full torque.
private float maximumForcePerSecondHow fast the torque can change.
private float maximumSlidePerSecondSerialized but not read by this class.
private FloatEvent progressChangedFloat event invoked with the progress when it changes.
private RopeBelt ropeBeltThe rope belt that moves with the handle.
private Motor ropeBeltMotorSerialized but not read by this class.
private Pickup ropeGrabThe pickup players grab.
private Interactable ropeLengthThe rope's interactable; grabs on it go to the handle and it's the handle's parent.
private float syncedProgressProgress last received from the server.
private MethodSyncStruct<bool> syncProgressMethod sync for progress.
private IUnityUpdateMethod updateTilStoppedHandle of the UpdateTilStopped update.
private IUnityUpdateMethod updateWithoutIkHandle of the per-frame update for holders without player IK.
private float yMaximumHighest local position of the handle on the rope.
private float yMinimumLowest local position of the handle on the rope.

Properties​

MemberWhat it is
float Progress { get; }Current progress along the rope, 0 to 1 (can leave that range when infinite or looping).

Events​

MemberWhat it is
event Action<float, float> ProgressChangedRaised with the old and new progress whenever it changes.

Methods​

MemberWhat it is
override void Initialize()Forwards rope grabs to the handle, hooks grab start and end, raises the starting progress and creates the sync.
override void OnConnected(Player player)Sends the current progress to a joining player, snapping.
void SetProgress(float value)Sets progress directly and raises the events (old value reported as 0).
11 private and internal methods
MemberWhat it is
private void CheckClamp()Keeps progress within 0 to 1 unless infinite or looping; with isGrabClamped it also moves the hand point back by the overshoot.
private void IkUpdated()Runs UpdatePosition before the holding player's IK each frame (or every Update for non-player holders).
private void InteractionEnded(Interactable interactable, Interactor interactor)Stops following the hand, keeps updating until the belt stops, and re-parents the handle to the rope.
private void InteractionStarted(Interactable interactable, Interactor interactor)Starts following the grabbing hand, cancelling any sync blend in progress.
private void OnDestroy()Removes the update.
private void OnDrawGizmosSelected()Draws the handle's vertical travel range in the editor.
private void OnProgressChanged(float oldProgress, float newProgress)Invokes the progressChanged Unity event and the ProgressChanged C# event.
private void OnValidate()Raises the progress events in the editor so linked objects preview the value.
private void SyncProgress(IPlayer player, Stream stream, bool isSnapping)Syncs progress. Clients snap when told to, otherwise blend towards it after the belt stops.
private void UpdatePosition(bool isStartingGrab)Pushes the belt with torque from the hand's movement, converts belt rotation into progress and places the handle.
private void UpdateTilStopped()Late update after letting go: blends to synced progress and, once the belt stops, ends and the server sends the final value.

Used in​

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