GridChase
namespace Griff.Scenes;
public sealed class GridChase : Component, IGridDriverSteps its GridMovement after a Target once it’s within Range, tile by tile and around walls, with no code: a roguelike’s monsters, a maze’s ghosts, a dungeon’s slimes. It stops next to the target (see StopDistance) and turns to face it, so an Attack swings its way. It steps as fast as its grid movement’s Step Time lets it, or with a TurnTaker that has actions, a step an action. With a GridPatrol too, it walks its route until it spots the target, and goes back to it once it gives up.
This is a component: its saved properties are on its component page.
Properties
Section titled “Properties”GiveUp
Section titled “GiveUp”public float GiveUp { get; set; }Once chasing, it gives up when the target gets this much further away than Range.
IsChasing
Section titled “IsChasing”public bool IsChasing { get; }True while it’s going after the target.
NeedsSight
Section titled “NeedsSight”public bool NeedsSight { get; set; }Only notice the target when nothing solid is in the way.
public float Range { get; set; }How close the target has to be to notice it, in world units. 0 notices it anywhere.
StopDistance
Section titled “StopDistance”public int StopDistance { get; set; }How many steps from the target it stops: 1 stops next to it (diagonally next to it too, if its grid movement is Diagonal; on a hex map, in any of the six hexagons round it), 2 keeps a cell between them, for one that shoots. 0 walks into the target’s cell; a target with a solid collider blocks it, so it bumps into it each step instead (Bumped, and its Bump Sound): a roguelike’s attack.
Target
Section titled “Target”public string? Target { get; set; }The name of the entity to chase, e.g. “Player”. In a network game it chases the nearest player.
TargetEntity
Section titled “TargetEntity”public Entity? TargetEntity { get; set; }The entity it chases. Set it from a script to chase something without looking it up by name.
WasNear
Section titled “WasNear”public bool WasNear { get; }Whether it was within its stop distance last time it looked, so Reached is raised once each time it gets there.
Methods
Section titled “Methods”Resume
Section titled “Resume”public void Resume(bool chasing, bool wasNear)Picks up where it was (a puzzle’s undo): whether it was chasing, and whether it was near.
Events
Section titled “Events”Reached
Section titled “Reached”public event Action<GridChase>? ReachedRaised when it gets within StopDistance steps of the target.
Spotted
Section titled “Spotted”public event Action<GridChase>? SpottedRaised when it notices the target and starts chasing.