# Hit

> Talos 0.7 · Since 0.6; changed in 0.7

Result of a raycast or shape cast.

A cast that hits nothing answers `null`, never `undefined`.

## Signature

```ts
export interface Hit {
  /** The entity whose collider was hit. */
  entity: EntityHandle
  /** Where the cast met it, world space, metres. */
  point: Vec3
  /** The surface normal at `point`. */
  normal: Vec3
  /** From the ray's `from` (or the shape's start) to the hit, in metres: `dir` is normalised first, so this is a length, not a multiple of `dir`. */
  distance: number
  /** Present only when the hit was on an instanced mesh: the stable id of the instance hit (see {@link Instances}). Absent for every other hit. */
  instance?: number
}
```

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

## Members

| Member | Signature | Description |
|---|---|---|
| `entity` | `entity: EntityHandle` | The entity whose collider was hit. |
| `point` | `point: Vec3` | Where the cast met it, world space, metres. |
| `normal` | `normal: Vec3` | The surface normal at `point`. |
| `distance` | `distance: number` | From the ray's `from` (or the shape's start) to the hit, in metres: `dir` is normalised first, so this is a length, not a multiple of `dir`. |
| `instance` | `instance?: number` | Present only when the hit was on an instanced mesh: the stable id of the instance hit (see {@link Instances}). Absent for every other hit. |

## Example

The tested fixture `fixtures/host/door.ts`.

```ts
import type { Behavior } from "@argus/api"
// docs/API.md, "Joints": a door on a hinge that swings open while the player is near and closes
// behind them. Typechecked by packages/api's tests.
export default {
  update(ctx) {
    const player = ctx.world.find("player")
    const near = player !== null && ctx.entity.distanceTo(player) < 2
    ctx.joint?.setMotor(near ? Math.PI / 2 : 0, { mode: "position", maxForce: 200 })
  },
} satisfies Behavior
```
