Skip to content

Chase

Chase walks an entity toward the nearest hero. The hero is the entity with the Hero trait, which the Player component spawns.

Its props are in ChaseProps.

Chase walks toward the nearest hero, level with the ground, and stops within reach. It moves the entity; it does not turn it, so a model that should face the way it walks needs its own facing. The five body fields are the walker’s: the physics cuts its capsule to them and climbs and slides by them, and a field changed later reaches it from the next step.

A chaser walks through the players by default: its collides leaves out CollisionLayer.Players, so a player walks through a chaser and a chaser through a player, in the room and on every client alike. A crowd of monsters never pins a player where she stands. A game that wants its monsters to block the players lists Players again:

import {
Chase,
chaserCollides,
CollisionLayer,
Entity,
type EntityProps,
} from "@daniel-zarinski/engine";
const blockingChaserCollides = [...chaserCollides, CollisionLayer.Players];
export function Guard({ position }: Pick<EntityProps, "position">) {
return (
<Entity model="yeti" position={position}>
<Chase speed={4} collides={blockingChaserCollides} />
</Entity>
);
}

A chaser ignores other chasers by default too: its collides leaves out CollisionLayer.Walkers, so its sweep never tests another walker’s capsule and a crowd costs the room no more than the same chasers spread apart. Chase keeps the crowd apart itself, moving any two chasers closer than their two radii to that distance each step. Two colliders meet only when each lists the other’s layer: a monster that must block a doorway lists Walkers again, and it stops the walkers that list Walkers too, not a chaser in the default. Player lists the layers.

Server. Chase has a consequence: it moves the entity toward a hero.

import { Entity, Chase, type EntityProps } from "@daniel-zarinski/engine";
export function Yeti({ position }: Pick<EntityProps, "position">) {
return (
<Entity model="yeti" position={position}>
<Chase speed={4} />
</Entity>
);
}