Trigger
Trigger fires a callback the frame the hero comes within a radius of an entity, and another the frame she leaves. The hero is the entity with the Hero trait, which the Player component spawns.
Its props are in TriggerProps.
The step marks inside while the hero stands within radius and counts each crossing in crossings. Trigger fires every crossing outside the step, in order, so a hero who passes straight through between two rendered frames still fires onEnter and then onExit. A callback is allowed here because Trigger is client behaviour.
Where it runs
Section titled “Where it runs”Client. The callbacks only change what this client shows.
import { useState } from "react";import { Entity, Spin, Trigger, Modal, Button } from "@daniel-zarinski/engine";
export function Goal() { const [won, setWon] = useState(false);
return ( <Entity position={[0, 0, -10]}> <Spin speed={0.6} /> <Trigger onEnter={() => setWon(true)} /> <mesh> <torusGeometry args={[0.8, 0.3, 16, 32]} /> <meshNormalMaterial /> </mesh> <Modal open={won} title="You made it" pause> <Button onPress={() => setWon(false)}>Play again</Button> </Modal> </Entity> );}