Skip to main content

ThrowablePickup

An abstract class in Root.Township, the global namespace.

Base for pickups that act on themselves in flight after being thrown, such as turning to face their direction of travel. Subclasses implement ThrowBehaviour, which runs each physics step until the pickup hits something, is grabbed or is docked.

Constructors​

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

Fields​

MemberWhat it is
protected Pickup pickupThe pickup on this object.
4 private and internal fields
MemberWhat it is
private float currentTimeNormalised time since the throw, 0 to 1.
private AnimationCurve lerpOverTimeCurve giving the behaviour's strength over normalised flight time.
private float minVelocitySquaredSquared speed below which the behaviour doesn't run.
private float timeToFullLerpSeconds for currentTime to reach 1.

Methods​

MemberWhat it is
protected virtual void ResetValues()Resets the lerp time to 0; subclasses can reset their own state too.
protected abstract void ThrowBehaviour(Vector3 velocity, float throwMagnitude)What the subclass does each physics step in flight, given the velocity and a 0 to 1 strength from lerpOverTime.
7 private and internal methods
MemberWhat it is
private void Awake()Hooks release, grab and dock events and starts disabled.
private void CheckStart(Interactable interactable, Interactor interactor)Enables the flight behaviour once nobody is holding the pickup.
private void DockedEndAlign(Interactor interactor, Pickup pickup, PickupDock dock)Stops the flight behaviour when the pickup is docked.
private void FixedUpdate()Advances the lerp time and calls ThrowBehaviour with the velocity and curve weight while moving fast enough.
private void InteractEndAlign(Interactable interactable, Interactor interactor)Stops the flight behaviour when the pickup is grabbed.
private void OnCollisionEnter(Collision collision)Stops the flight behaviour on any collision.
private void OnEnable()Resets the values when the flight starts.