Skip to main content

ActiveCrawl

A class in Root.Township, Alta.Intelligence.

Server: running action that makes a creature crawl over any surface (walls, ceilings) by moving its transform along raycast hits, turning at random. Settings come from AgentCrawlSettings.

Constructors​

MemberWhat it is
ActiveCrawl()Creates an ActiveCrawl with default values.

Fields​

12 private and internal fields
MemberWhat it is
private float beganFacingWallTime the creature started facing the current wall.
private Quaternion currentRotationThe crawl rotation, aligned with the surface it's on.
private int frameCountFrames since the last raycast check.
private Color hitColorDebug colour for the kind of surface hit last. Not drawn anywhere in this build.
private bool isFacingWallWhether the creature is blocked by something ahead.
private Vector3 lastHitThe last surface point the creature was moved to.
private float maxTimeFacingWallSeconds the creature stays facing a wall before picking a new heading. 2.
private Vector3 targetWalkDirectionThe heading the creature is turning towards.
private Transform transformThe creature's rigidbody transform, moved directly.
private IUnityUpdateMethod updateThe registered Walk update.
private static UpdateModule updateModuleShared "Crawler Helper" update module that runs Walk.
private Vector3 walkDirectionThe current walking direction.

Methods​

MemberWhat it is
override void Update(bool hasTarget)Does nothing. The movement runs in Walk every frame instead.
protected override void OnStart()Sets a random duration, stores the starting rotation, picks a heading and registers Walk on its own update module.
4 private and internal methods
MemberWhat it is
private void CancelAction(IActiveAction finished)Deregisters the crawl update when the action ends.
private void GetNewWalkDirection()Picks a new heading up to 90 degrees either side, or further when facing a wall.
private void MoveTo(Vector3 point, Vector3 normal)Puts the creature at a surface point and turns it towards the surface normal and walk direction.
private void Walk()Per frame: moves forward and steers to the heading. Every few frames raycasts to follow surfaces, turn at walls, or switch to the recover-from-falling set.