Skip to main content

IndependentWalker

A class in Root.Township, Alta.Pathfinding.

Lets an Agent's navigator child detach and walk on its own, while the agent's rigidbody follows and turns toward it each frame. Sits next to a Navigator.

Constructors​

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

Fields​

9 private and internal fields
MemberWhat it is
private Agent baseTopicThe agent whose rigidbody follows this walker.
private Transform cachedTransformCached transform of the walker.
private bool isAttachedWhether the walker is parented to the agent and not driving it.
private bool isFollowingByDefaultDetaches on Start so the agent follows from the beginning.
private float movementSpeedMetres per second the agent moves toward the walker.
private Navigator navigatorThe Navigator on the same object, teleported on detach.
private float rotationSpeedDegrees per second the agent turns toward the walker.
private static UpdateModule updateModuleShared update module for all independent walkers.
private IUnityUpdateMethod updatePositionThe registered UpdatePosition method while detached.

Methods​

MemberWhat it is
void Attach()Reparents the walker under the agent at zero offset and stops following. Destroys itself if the agent is gone.
void Dettach()Unparents the walker, teleports its navigator to where it is and starts moving the agent toward it.
7 private and internal methods
MemberWhat it is
private void BaseDestroyed(NetworkEntity entity, bool isUnload)Destroys the walker when the agent's entity is destroyed.
private void Destroyed()Unhooks from the agent, destroys the walker's GameObject and stops the update.
private void InternalDettach(bool isRepositioning)Detaches if attached and the agent is alive, hooks the agent's death and destroy events, and starts UpdatePosition.
private void OnBaseKilled(DamageData lastHit)Destroys the walker when the agent dies.
private void OnDestroy()Removes the update method.
private void Start()Caches the transform and detaches straight away when isFollowingByDefault is on.
private void UpdatePosition()Moves the agent's rigidbody toward the walker at movementSpeed and turns it toward the walker at rotationSpeed.