# BusCharacterSqueezed

> Talos 0.7 · Since 0.6

Payload of the engine-published `"character-squeezed"` event: a moving body is closing on a character ({@link Controller.squeezedBy}) — a door coming down on it, a lift carrying it up into a ceiling.

The engine never pushes a character through the floor or a wall to make room; it leaves it where it is and raises this once when the squeeze starts (per character and mover; again after a release), after the controllers step and before behaviours' `update`; the ongoing state is {@link Controller.squeezedBy}, with `by` of the bus record null. The game decides: reverse the door, stop the lift, hurt the character. `ts // A door that never closes on anyone: reverse when it is the mover named. init(ctx) { ctx.events.on("character-squeezed", (ev) => { if (ev.data.by === ctx.entity.id) ctx.state.opening = true }) } ```

## Signature

```ts
export interface BusCharacterSqueezed {
  /** Id of the character being squeezed. */
  character: string
  /** Id of the moving body doing it: the door, the lift — never the still ceiling. */
  by: string
}
```

Import: `import type { BusCharacterSqueezed } from "@argus/api"`

## Members

| Member | Signature | Description |
|---|---|---|
| `character` | `character: string` | Id of the character being squeezed. |
| `by` | `by: string` | Id of the moving body doing it: the door, the lift — never the still ceiling. |

## Example

The tested fixture `fixtures/recipes/collectible-and-goal/scenes/behaviors/collectible.ts`.

```ts
import type { Behavior } from "@argus/api"

/**
 * A coin the player collects by walking into it.
 *
 * It says so once, as `collected`, and leaves the world. Counting is somebody else's job —
 * `goal-exit.ts` — so a coin never needs to know how many there are.
 *
 * The contact is `onTrigger`, which needs three things in the scene: a collider with
 * `isTrigger: true` (the volume), a `trigger` component (what fires), and a body on the player —
 * the character controller's capsule is one.
 */
interface State {
  collected: boolean
}

interface Props {
  /** Tag the toucher must carry. Default `player`. */
  playerTag?: string
}

export default {
  init(ctx) {
    if (typeof ctx.state.collected !== "boolean") ctx.state.collected = false
  },

  onTrigger(ctx, trigger) {
    if (ctx.state.collected || !trigger.entering) return
    if (!trigger.other.hasTag(ctx.props.playerTag ?? "player")) return
    ctx.state.collected = true
    // The `goal` component on this coin has the same id, so the playtester and the HUD agree.
    ctx.events.emit("collected", { goal: ctx.entity.id })
    // Last: after `despawn` every member of this entity's handles throws.
    ctx.entity.despawn()
  },
} satisfies Behavior<State, Props>
```
