Skip to content

GridChase

namespace Griff.Scenes;
public sealed class GridChase : Component, IGridDriver

Steps 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.

public float GiveUp { get; set; }

Once chasing, it gives up when the target gets this much further away than Range.

public bool IsChasing { get; }

True while it’s going after the target.

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.

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.

public string? Target { get; set; }

The name of the entity to chase, e.g. “Player”. In a network game it chases the nearest player.

public Entity? TargetEntity { get; set; }

The entity it chases. Set it from a script to chase something without looking it up by name.

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.

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.

public event Action<GridChase>? Reached

Raised when it gets within StopDistance steps of the target.

public event Action<GridChase>? Spotted

Raised when it notices the target and starts chasing.