Skip to main content

HoverPickup

A class in Root.Township, the global namespace.

Makes a pickup float back to a set spot when let go, like the menu and customization orbs. Works locally, or only on the server when networked.

Constructors​

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

Fields​

MemberWhat it is
protected bool isNetworkedWhether only the server moves it back.
protected Pickup pickupBacking field for Pickup.
protected bool teleportToTargetOnReleaseDespite the name, true makes it fly back smoothly; false snaps it after the delay.
13 private and internal fields
MemberWhat it is
private float accelerationHow fast the pickup accelerates while flying back.
private Transform cachedParentThe pickup's original parent, restored on snap.
private bool isAlwaysReturningIf true, the pickup's start pose is used as its return target when none was set.
private bool isMaintainingParentIf true, the target is stored in the parent's local space and the pickup is re-parented on snap.
private bool isPositionSetTrue once a return target has been set.
private float moveSpeedTop speed while flying back.
private Vector3 positionReturn target position (local when isMaintainingParent).
private Coroutine returningThe running return coroutine, if any.
private float returnPositionThresholdSquared distance at which the return counts as arrived and snaps.
private Quaternion rotationReturn target rotation (local when isMaintainingParent).
private float rotationLerpSpeedHow fast the rotation turns toward the target while returning, faster when close.
private FauxRigidbody selectionOrbRigidbodyFaux rigidbody used to move the pickup while it returns.
private float snapDelayInSecondsDelay before snapping back when teleportToTargetOnRelease is off.

Properties​

MemberWhat it is
Pickup Pickup { get; }The pickup being returned.

Methods​

MemberWhat it is
void SetTarget(Transform target)Sets the spot to return to, from a transform or a position and rotation.
void SetTarget(Vector3 position, Quaternion rotation)Sets the spot to return to, from a transform or a position and rotation.
void Snap()Puts the pickup straight onto its spot and stops it.
async void SnapWithDelay()Snaps after the snap delay.
protected virtual void Awake()Hooks grab and release on the pickup.
protected bool CanExecute()True when not networked, or networked and on the server.
protected virtual void HandleGrabbed(Interactable interactable, Interactor interactor)Stops returning when grabbed.
protected virtual void OnDestroy()Stops all coroutines.
protected virtual void OnReturning(Vector3 direction, float velocity)Hook called each frame while flying back, with direction and speed. Does nothing by default.
protected virtual void Start()Remembers the parent and, if no target is set, uses the current position as the target.
protected virtual void StartMovingBack(Interactable interactable, Interactor interactor)On release, starts returning to the spot if one is set.
protected void StopReturning()Stops the return coroutine.
2 private and internal methods
MemberWhat it is
private void GetTarget(out Vector3 position, out Quaternion rotation, out float scale)Works out the world position, rotation and scale to return to, in parent space when isMaintainingParent is set.
private IEnumerator ReturnToPosition() (iterator)Coroutine that flies the released pickup back to its target with faux physics, then snaps it in place.

Used in​

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