Skip to main content

StabilizePickupJoint

A class in Root.Township, Alta.Inventory.

Keeps a jointed pickup (such as a bag on a joint) stable: limits its distance and speed while held, and rebuilds the joint when the player teleports.

Constructors​

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

Fields​

22 private and internal fields
MemberWhat it is
private Transform cachedTransformCached transform of the pickup.
private Vector3 centerOfGravityCentre of mass set on the joint body.
private TransformSave defaultJointBodyLocalThe joint body's default local pose.
private bool isMovingParentWhether the pickup is parented to the player during teleports. True unless it uses a velocity joint.
private bool isUnchildingJointWhether the joint body is moved out of the pickup's hierarchy.
private ConfigurableJoint jointBacking field for Joint.
private TransformSave jointBodyLocalJoint body pose saved before a teleport.
private Vector3 jointLocalPositionLocal position of the joint body when docked or undocked.
private Quaternion jointLocalRotationLocal rotation of the joint body when docked or undocked.
private NetworkRigidbody jointNetworkRigidbodyNetwork sync for the joint body, turned off while held or docked.
private Rigidbody jointRigidbodyThe rigidbody hanging off the joint.
private Transform jointRigidbodyTransformCached transform of the joint body.
private JointSettings jointSettingsJoint settings saved while the joint is removed.
private static Logger loggerLogger for this class.
private float maxAngularVelocitySpin limit for the joint body while held.
private float maxDistanceFurthest the joint body may be from the grip point while held.
private float maxDistanceOnRepositionSquaredSquared grip distance beyond which the whole pickup snaps to the grip.
private float maxVelocitySpeed limit for the joint body while held.
private Pickup pickupBacking field for Pickup.
private Transform previousParentParent the joint body was unchilded to.
private AltaCoroutine recreateJointRoutineThe running joint rebuild coroutine.
private IUnityUpdateMethod updateRigidbodyPositionThe registered fixed update that clamps the body.

Properties​

MemberWhat it is
ConfigurableJoint Joint { get; }The configurable joint. Null for a moment while it's being rebuilt after a teleport.
Pickup Pickup { get; }The pickup this stabilizes.

Methods​

MemberWhat it is
void ApplyDefaultChildPosition()Stops the joint body and puts it back to its saved default local pose.
protected virtual void Docked(Interactor interactor, Pickup pickup, PickupDock dock)Places the joint body at its docked local pose and stops its network sync; kinematic unless the dock allows physical joints.
protected virtual void StartHandlingToPositionChanges(Interactable interactable, Interactor interactor)When grabbed, clamps the body each fixed update, turns off its network sync and follows player teleports.
protected virtual void StopHandlingToPositionChanges(Interactable interactable, Interactor interactor)When released, turns network sync back on (unless docked) and stops following teleports.
protected virtual void Undocked(Interactor interactor, Pickup pickup, PickupDock dock)Makes the joint body physical again and turns network sync back on if not held.
15 private and internal methods
MemberWhat it is
private void Awake()Caches transforms, saves the default joint body pose and sets the centre of mass.
private void IPostboxPopped.HandlePostPopped()When popped from a postbox, resets the joint body to its default pose.
private void MoveWithPlayer(PlayerController player, Vector3 oldPosition, Vector3 newPosition, LocomotionFunction function)After the move, restores the body pose and starts rebuilding the joint next fixed update.
private void OnDestroy()Stops the fixed update and the rebuild coroutine.
private void OnDisable()Unhooks the events and stops the fixed update.
private void OnDrawGizmosSelected()Draws the centre of gravity.
private void OnEnable()Hooks the pickup's dock and interaction events.
private void OnValidate()Editor: fills jointRigidbody from the child joint's connected body if empty.
private void RecordLocalPositionBeforeMoving(PlayerController player, Vector3 oldPosition, Vector3 newPosition, LocomotionFunction function)Before a teleport, reposition or recovery, saves the body pose, removes the joint and parents to the player.
private void RecreateJoint()Recreates the joint from the saved settings.
private IEnumerator RecreateJointInNextFrame() (iterator)Coroutine that waits a fixed update, rebuilds the joint and makes the body physical again.
private void SetRigidbodiesPosition()Pulls the joint body back within maxDistance of the grip and clamps its speeds.
private void SetRigidbodiesPosition(Vector3 gripPointPosition)Pulls the joint body back within maxDistance of the grip and clamps its speeds.
private void Start()Unparents the joint body if isUnchildingJoint is set.
private void UnchildJoint()Moves the joint body up to the pickup's parent, if isUnchildingJoint is set.