@ferret/physics-gravity
gravity as a field with uniform vectors per scope and point attractors.
gravity as a field. A uniform vector (override per zone, level or entity), point attractors (a planet, a pit,
inverse square with a softening radius so nothing divides by zero), and a scale per body or entity. With G on, the kernel's
own constant gravity is switched off and this field supplies every force, so one law serves the cannonball, the character
(which reads host.fields.gravity) and anything a game adds.
Read the guide: how to use it →
Functions
gravity function
function gravity(): GravityCapabilitypackages/physics-gravity/src/index.ts:41
Interfaces
Attractor interface
interface Attractorgravity as a field. A uniform vector (override per zone, level or entity), point attractors (a planet, a pit,
inverse square with a softening radius so nothing divides by zero), and a scale per body or entity. With G on, the kernel's
own constant gravity is switched off and this field supplies every force, so one law serves the cannonball, the character
(which reads host.fields.gravity) and anything a game adds.
id: string | |
position?: Vec3 | a fixed point, or an entity whose node is the centre |
entity?: string | |
mu?: number | gravitational parameter G·M (m³/s²); or give the surface gravity and the radius of the body |
surfaceGravity?: number | |
radius?: number | |
softening?: number | below this distance the pull stops growing (default 0.1 × radius, or 0.5 m) |
range?: number | beyond this distance the attractor does nothing (default: unlimited) |
packages/physics-gravity/src/index.ts:10
GravityCapability interface
interface GravityCapability extends Capabilityattractors: Map<string, Attractor> | |
addAttractor(a: Attractor): void | |
removeAttractor(id: string): void | |
at(host: PhysicsHost, p: Vec3, ctx?: ScopeContext): Vec3 | Gravity acceleration at a point (m/s²): the field vector of its scope plus every attractor, times the scale. |
packages/physics-gravity/src/index.ts:27
Constants
GRAVITY_DEFAULTS const
const GRAVITY_DEFAULTS: { vector: Vec3; scale: number; }packages/physics-gravity/src/index.ts:25