VehicleWater
Since 0.7
{@link Vehicle.water}: a watercraft's or an amphibious vehicle's water handling, as of the last tick.
ts // Spray from the bow at speed, and a thump when the hull slams back down. update(ctx) { const w = ctx.vehicle?.water if (!w) return if (w.bowWet && w.speed > 6) ctx.hud.set("spray", Math.round(w.speed)) if (w.slam > 0) ctx.log("slam", w.slam) }
Signature
export interface VehicleWater {
/** Forward speed relative to the water under the hull, m/s; negative going astern. */
readonly speed: number
/** How far onto the plane the hull is, 0..1. */
readonly planing: number
/** The hull's submerged share, 0..1. */
readonly immersion: number
/** How much of the handling is the water's, 0..1: 1 afloat, 0 on its wheels. */
readonly blend: number
/** True while it is upside down or on its side (tilted past about 100°), until it is back within 60° of upright. */
readonly capsized: boolean
/** The bow, world space. */
readonly bow: Vec3
/** Whether the bow is under the surface. */
readonly bowWet: boolean
/** Whether any thruster is in the water. */
readonly sternWet: boolean
/** Total thrust applied, newtons, negative in reverse. */
readonly thrust: number
/** The downward speed, m/s, of the hull hitting the water on this tick; 0 on every other tick. */
readonly slam: number
/** Slams since the vehicle was built. */
readonly slams: number
}
Import: import type { VehicleWater } from "@argus/api"
Members
| Member | Signature | Description |
|---|---|---|
speed | readonly speed: number | Forward speed relative to the water under the hull, m/s; negative going astern. |
planing | readonly planing: number | How far onto the plane the hull is, 0..1. |
immersion | readonly immersion: number | The hull's submerged share, 0..1. |
blend | readonly blend: number | How much of the handling is the water's, 0..1: 1 afloat, 0 on its wheels. |
capsized | readonly capsized: boolean | True while it is upside down or on its side (tilted past about 100°), until it is back within 60° of upright. |
bow | readonly bow: Vec3 | The bow, world space. |
bowWet | readonly bowWet: boolean | Whether the bow is under the surface. |
sternWet | readonly sternWet: boolean | Whether any thruster is in the water. |
thrust | readonly thrust: number | Total thrust applied, newtons, negative in reverse. |
slam | readonly slam: number | The downward speed, m/s, of the hull hitting the water on this tick; 0 on every other tick. |
slams | readonly slams: number | Slams since the vehicle was built. |
Example
The tested fixture fixtures/host/hover.ts.
import type { Behavior, Ctx, Vec3 } from "@argus/api"
// docs/API.md, "Forces, torques and impulses": a body that hovers (thrust = m·g), and the same lift
// as four rotors in the airframe's own frame plus a yaw torque. Typechecked by packages/api's tests.
const HUBS: Vec3[] = [[0.3, 0, 0.3], [-0.3, 0, 0.3], [0.3, 0, -0.3], [-0.3, 0, -0.3]]
function hover(ctx: Ctx) {
const body = ctx.body
if (!body) return
if (ctx.props["rotors"] !== true) {
body.addForce([0, body.mass * 9.81, 0])
return
}
for (const h of HUBS) body.addForceAtPoint([0, (body.mass * 9.81) / 4, 0], h, "local")
body.addTorque([0, (ctx.props["yaw"] as number | undefined) ?? 0, 0], "local")
}
export default {
// The first physics step runs before the first update; this is its thrust.
init(ctx) { hover(ctx) },
update(ctx) { hover(ctx) },
} satisfies Behavior