Skip to main content

VerticalFlyingController

A class in Root.Township, the global namespace.

Makes a flying object bob up and down over the ground. The server picks random target heights and both sides push the rigidbody's vertical velocity toward the target; it stops while the optional pickup is held or docked.

Constructors​

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

Fields​

13 private and internal fields
MemberWhat it is
private float accelerationVertical acceleration per second toward the target.
private Vector3 cachedPositionDeclared but never used.
private bool isHeldOrDockedWhether the pickup is held or docked right now.
private float maxVelocityCap on vertical speed.
private AnimationCurve modulatorCurve sampled with a random value to size each move, as a fraction of movementAmplitude.
private float movementAmplitudeHighest target height above the ground.
private float movingTowardsCurrent target height above the ground. Only the server picks it; it isn't synced here.
private float nextSignDirection of the next move. Flips each time a target is picked.
private Pickup pickupOptional pickup. While it's held or docked the movement stops.
private Rigidbody rigidbodyThe rigidbody whose vertical velocity is driven.
private IUnityUpdateMethod updatePositionHandle for the registered fixed-update method.
private bool usesNegativeValuesOnModulatorWhen true, the modulator is sampled with a signed input (-1 to 1) instead of 0 to 1.
private Walker walkerThe Walker that gives DistanceToGround.

Methods​

MemberWhat it is
override void Initialize()Registers the server or client fixed-update method and hooks the pickup's grab and dock events.
7 private and internal methods
MemberWhat it is
private void DockedChanged(Interactor interactor, Pickup arg2, PickupDock arg3)Dock and undock handler for the pickup; calls UpdateControlled.
private void GetNewPosition()Server: picks the next target height, alternating up and down by an amount from modulator, kept between 0 and movementAmplitude.
private void InteractionChanged(Interactable interactable, Interactor interactor)Grab and release handler for the pickup; calls UpdateControlled.
private void OnDestroy()Deregisters the update method.
private void ServerUpdatePosition()Server fixed update: picks a new target once within 5 cm of the current one, then calls UpdatePosition.
private void UpdateControlled(Interactor interactor)Stops the movement while the pickup is held or docked and starts it again once it's free.
private void UpdatePosition()Accelerates the rigidbody's vertical velocity toward the target height, capped at maxVelocity.