Skip to content

Interact

Interact shows a prompt above an entity while the hero is near it, and fires a callback on a key press. The hero is the entity with the Hero trait, which the Player component spawns.

Its props are in InteractProps.

The prompt shows while the hero is near, and the E key fires onInteract. A callback is allowed here because Interact is client behaviour.

Client. The prompt only changes what this client shows.

import { Entity, Interact, type EntityProps } from "@daniel-zarinski/engine";
export function Chest({
position,
onInteract,
}: Pick<EntityProps, "position"> & { onInteract: () => void }) {
return (
<Entity model="chest" position={position}>
<Interact prompt="Open" onInteract={onInteract} />
</Entity>
);
}