Skip to main content

LerpFollowBase<T>

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

Makes an object trail smoothly after a target's position plus an offset, in late update. Off on a dedicated server by default. LerpFollow and ScaledLerpFollow derive from it.

Constructors​

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

Fields​

MemberWhat it is
protected Transform cachedTransformThis object's transform.
protected Vector3 oldPositionPosition from the last update.
5 private and internal fields
MemberWhat it is
private bool isDisabledOnServerWhen true, the component turns itself off on a server, except in a local test.
private float lerpPerSecondHow fast it catches up with the target.
private static UpdateModule staticUpdateModuleShared LateUpdate module for all followers of this target type.
private IUnityUpdateMethod updateModuleThis follower's registration in the update module.
private Vector3 worldOffsetWorld offset from the target position. Defaults to 0.5 up.

Properties​

MemberWhat it is
abstract T Target { get; }The thing being followed. Following stops when it becomes null.
protected abstract Vector3 TargetPosition { get; }World position of the target.

Methods​

MemberWhat it is
virtual void SetTarget(T target)Enables following when the target is not null.
virtual void Start()Snaps to the target, and disables itself on a server unless that is turned off.
protected virtual void Moving(Vector3 from, Vector3 to)Called each update with the old and target positions, for subclasses.
3 private and internal methods
MemberWhat it is
private void MovementUpdate()Runs in LateUpdate. Moves towards the target plus worldOffset by lerpPerSecond of the gap each second, or disables itself if the target is gone.
private void OnDisable()Stops the movement update.
private void OnEnable()Registers the movement update with the shared update module.