Talos docs

VehicleWater

Since 0.7

{@link Vehicle.water}: a watercraft's or an amphibious vehicle's water handling, as of the last tick.

Plain text

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

MemberSignatureDescription
speedreadonly speed: numberForward speed relative to the water under the hull, m/s; negative going astern.
planingreadonly planing: numberHow far onto the plane the hull is, 0..1.
immersionreadonly immersion: numberThe hull's submerged share, 0..1.
blendreadonly blend: numberHow much of the handling is the water's, 0..1: 1 afloat, 0 on its wheels.
capsizedreadonly capsized: booleanTrue while it is upside down or on its side (tilted past about 100°), until it is back within 60° of upright.
bowreadonly bow: Vec3The bow, world space.
bowWetreadonly bowWet: booleanWhether the bow is under the surface.
sternWetreadonly sternWet: booleanWhether any thruster is in the water.
thrustreadonly thrust: numberTotal thrust applied, newtons, negative in reverse.
slamreadonly slam: numberThe downward speed, m/s, of the hull hitting the water on this tick; 0 on every other tick.
slamsreadonly slams: numberSlams 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