Skip to main content

MovePickup

A class in Root.Township, the global namespace.

An object that slides along one axis when players grab and pull its handles, like a heavy door or lift. The server works out the force from hand positions with a PID controller and syncs movement and speed.

Constructors​

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

Fields​

MemberWhat it is
static AccumulativeAverageCount prepareForWriteTimerShared timing stat for all MovePickups.
static AccumulativeAverageCount serializeTimerShared timing stat for all MovePickups.
20 private and internal fields
MemberWhat it is
private float bottomBounceShare of speed reversed when it hits the bottom.
private float[] forcePerHandMaximum force by number of hands holding (1 to 4).
private bool isDisablingNot used.
private float maxDistanceHow far it can move along the axis.
private float maxHandDistanceCap on how much one hand's pull counts.
private float maximumNegativeSpeedFastest speed moving back down the axis.
private float maximumPositiveSpeedFastest speed moving up the axis.
private float movementCurrent distance from the start position. Saved.
private Vector3 movementAxisLocal axis it moves along. Set to up if left at zero.
private float negativeForceConstant force pushing it back toward the start, like gravity.
private Pickup[] pickupsHandle pickups whose grabs move it.
private PidController pidControllerPID controller that turns hand pull into force.
private PidController.Setup pidSetupPID gains for the controller.
private Dictionary<Interactor, Vector3> relativeGrabsServer: each holding hand and where it first grabbed, in local space.
private Vector3 startingPositionLocal position at rest.
private float syncMovementLast movement value sent or received.
private float syncVelocityLast speed value sent or received.
private float topBounceShare of speed reversed when it hits the top.
private IUnityUpdateMethod updateFixed update registration. Removed once it rests at the bottom with no hands.
private float velocityCurrent speed along the axis. Saved.

Properties​

3 private and internal properties
MemberWhat it is
private int Alta.Networking.INetworkSerialized.MaximumBits { get; }Always 32.
private AccumulativeAverageCount Alta.Networking.INetworkSerialized.PrepareForWriteTimer { get; }Shared timing stat for PrepareForWrite.
private AccumulativeAverageCount Alta.Networking.INetworkSerialized.SerializeTimer { get; }Shared timing stat for Serialize.

Methods​

10 private and internal methods
MemberWhat it is
private void Awake()Stores the start position, creates the PID controller and hooks grab start and end on each handle pickup.
private void Ended(Interactable interactable, Interactor interactor)Forgets a hand that let go.
private void OnDestroy()Stops the fixed update.
private void OnDrawGizmosSelected()Draws the movement axis in the editor.
private void OnValidate()Pushes changed PID values to the running controller.
private bool Alta.Networking.INetworkSerialized.PrepareForWrite(bool isWriteFull)Returns true if movement or speed changed since the last sync.
private void RunFixedUpdate()Server: adds force from how far hands pulled along the axis. Both: applies the downward force, bounces at the ends and moves the object.
private void Alta.Networking.INetworkSerialized.Serialize(Stream stream, bool isWriteFull)Syncs movement and speed, or a single bit when both are zero. Client: applies them and starts updating.
private void Started(Interactable interactable, Interactor interactor)Records where a hand grabbed and starts updating.
private void StartUpdate()Registers the fixed update if it isn't running.