PickOptions
Since 0.6
Options for {@link WorldQuery.pick}.
Signature
export interface PickOptions {
/** Sweep a sphere of this radius instead of a thin ray, metres — easier to aim at something small. Default 0. */
radius?: number
/** Whether a trigger volume stops the pick. Default **false**, unlike `raycast`: a pick sees through volumes. */
triggers?: boolean
/** What the pick passes through — the picker, whose own collider a ray from its eye starts inside. */
exclude?: EntityHandle | string | (EntityHandle | string)[]
/** A body heavier than this, kg, answers null. */
maxMass?: number
/** Only an entity with this tag answers; anything else in the way answers null. */
tag?: string
}
Import: import type { PickOptions } from "@argus/api"
Members
| Member | Signature | Description |
|---|---|---|
radius | radius?: number | Sweep a sphere of this radius instead of a thin ray, metres — easier to aim at something small. Default 0. |
triggers | triggers?: boolean | Whether a trigger volume stops the pick. Default false, unlike raycast: a pick sees through volumes. |
exclude | exclude?: EntityHandle | string | (EntityHandle | string)[] | What the pick passes through — the picker, whose own collider a ray from its eye starts inside. |
maxMass | maxMass?: number | A body heavier than this, kg, answers null. |
tag | tag?: string | Only an entity with this tag answers; anything else in the way answers null. |
Example
The tested fixture packages/critic/fixtures/play/door-and-key/locked-door.ts.
import type { Behavior } from "@argus/api"
/**
* A door that opens once something tagged `requiresTag` has been collected.
*
* It listens for `key-collected` carrying that tag and lifts itself out of the way. It is a
* kinematic body, so the physics layer follows the transform and the doorway becomes
* passable the tick after. Without a key in the scene the event never comes and the door
* stays shut — which is exactly the fault the playtester has to find.
*/
interface State {
open: boolean
}
interface Props {
/** The tag a collected item must carry. Default `key`. */
requiresTag?: string
/** Metres to lift the door when it opens. Default 4. */
lift?: number
}
export default {
init(ctx) {
if (typeof ctx.state.open !== "boolean") ctx.state.open = false
},
onEvent(ctx, event) {
if (ctx.state.open || event.name !== "key-collected") return
const wanted = ctx.props.requiresTag ?? "key"
const data = (event.data ?? {}) as { tag?: string }
if (data.tag !== wanted) return
ctx.state.open = true
ctx.entity.translate([0, ctx.props.lift ?? 4, 0])
ctx.events.emit("door-opened", { door: ctx.entity.id })
ctx.log("door opened")
},
} satisfies Behavior<State, Props>