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.
- Listed in Items, inventory and logic
- Inherits or implements
MonoBehaviour,IPostboxPopped - Derived types
StabilizeJointContainer - Attributes
RequireComponent
Constructors
| Member | What it is |
|---|---|
StabilizePickupJoint() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
22 private and internal fields
| Member | What it is |
|---|---|
private Transform cachedTransform | Cached transform of the pickup. |
private Vector3 centerOfGravity | Centre of mass set on the joint body. |
private TransformSave defaultJointBodyLocal | The joint body's default local pose. |
private bool isMovingParent | Whether the pickup is parented to the player during teleports. True unless it uses a velocity joint. |
private bool isUnchildingJoint | Whether the joint body is moved out of the pickup's hierarchy. |
private ConfigurableJoint joint | Backing field for Joint. |
private TransformSave jointBodyLocal | Joint body pose saved before a teleport. |
private Vector3 jointLocalPosition | Local position of the joint body when docked or undocked. |
private Quaternion jointLocalRotation | Local rotation of the joint body when docked or undocked. |
private NetworkRigidbody jointNetworkRigidbody | Network sync for the joint body, turned off while held or docked. |
private Rigidbody jointRigidbody | The rigidbody hanging off the joint. |
private Transform jointRigidbodyTransform | Cached transform of the joint body. |
private JointSettings jointSettings | Joint settings saved while the joint is removed. |
private static Logger logger | Logger for this class. |
private float maxAngularVelocity | Spin limit for the joint body while held. |
private float maxDistance | Furthest the joint body may be from the grip point while held. |
private float maxDistanceOnRepositionSquared | Squared grip distance beyond which the whole pickup snaps to the grip. |
private float maxVelocity | Speed limit for the joint body while held. |
private Pickup pickup | Backing field for Pickup. |
private Transform previousParent | Parent the joint body was unchilded to. |
private AltaCoroutine recreateJointRoutine | The running joint rebuild coroutine. |
private IUnityUpdateMethod updateRigidbodyPosition | The registered fixed update that clamps the body. |
Properties
| Member | What 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
| Member | What 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
| Member | What 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. |