Talos docs

PickHit

Since 0.7

What ctx.camera.pick answers: a {@link Hit}, whose entity is null for the ground-plane fallback.

Plain text

Signature

export interface PickHit extends Omit<Hit, "entity"> {
  /** The entity the ray hit; `null` when it met the `ground` plane instead of a collider. */
  entity: EntityHandle | null
}

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

Members

MemberSignatureDescription
entityentity: EntityHandle | nullThe entity the ray hit; null when it met the ground plane instead of a collider.

Example

The tested fixture fixtures/host/door.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