On this page
  1. Fields
    1. chasing
    2. sees
    3. from

rmp::behavior::Chase

behavior #include <rmp/behavior.h> include/rmp/behavior.h:865
struct Chase

Sees a target and goes after it. It sees it within sight units, inside a cone of fov degrees around the way it faces, and — with line_of_sight — when no solid map cell stands between them. While it chases, a Patrol on the same object is paused, and a Pathfind, when there is one, finds the way; without one it runs straight at the target. After lose_after seconds without seeing it, it gives up: on_lose, back home with return_home, and the Patrol resumes.

From the editor: "speed" (Float), "sight" (Float), "fov" (Float).

Added to an object with add<rmp::behavior::Chase>(); the framework calls its _ready, _update with the object it is on.

Fields

FieldTypeDefaultWhat it is
targetHandle<Object>

Whom it looks for; the game sets it, usually the player

speedfloat120

Units per second while it chases

sightfloat160

How far it sees; 0 = any distance

fovfloat360

Degrees of its view, centred on the way it faces

line_of_sightbooltrue

Solid map cells hide the target

lose_afterfloat2

Seconds without seeing it before it gives up

return_homebooltrue

Goes back where it started after giving up

stop_distancefloat0

Stops this close to the target

on_spotCallback<Object &, Object &>

(the chaser, the target), when a chase starts

on_loseCallback<Object &>

When it gives up

oursstruct { … }

What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then { .speed = 320 } stops compiling — which is the whole design. The name is the fence.

chasing

bool chasing() const

Whether it is chasing now.

sees

bool sees() const

Whether it saw the target at its last update.

from

static Chase from(const MapObject &object)

A Chase with the fields the map's entity has by these names — speed, sight, fov — and the defaults for the rest. See "FROM THE EDITOR" at the top of this file.