Hit
Since 0.6Changed in 0.7
Result of a raycast or shape cast.
A cast that hits nothing answers null, never undefined.
Signature
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/recipes/drone-search/scenes/behaviors/carrier.ts.
import type { Behavior } from "@argus/api"
/** Moves a kinematic body round `props.path` (world [x, z] points) at `props.speed` m/s, facing where it goes: the
* stand-in for a boat or a truck the drone launches from, and for the contact it looks for. */
interface Props {
path: [number, number][]
speed: number
}
interface State {
next: number
}
export default {
init(ctx) {
ctx.state.next ??= 0
},
update(ctx, dt) {
const path = ctx.props.path
const goal = path[ctx.state.next % path.length]
if (goal === undefined) return
const p = ctx.entity.position
const to: [number, number, number] = [goal[0], p[1], goal[1]]
ctx.entity.lookAt(to)
if (ctx.entity.moveToward(to, ctx.props.speed * dt)) ctx.state.next = (ctx.state.next + 1) % path.length
},
} satisfies Behavior<State, Props>