FERRETGame engine over Babylon.js
Ferret

@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.

4 exports · source in packages/physics-gravity/src

Functions

gravity function

function gravity(): GravityCapability

packages/physics-gravity/src/index.ts:41

Interfaces

Attractor interface

interface Attractor

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.

id: string
position?: Vec3a fixed point, or an entity whose node is the centre
entity?: string
mu?: numbergravitational parameter G·M (m³/s²); or give the surface gravity and the radius of the body
surfaceGravity?: number
radius?: number
softening?: numberbelow this distance the pull stops growing (default 0.1 × radius, or 0.5 m)
range?: numberbeyond this distance the attractor does nothing (default: unlimited)

packages/physics-gravity/src/index.ts:10

GravityCapability interface

interface GravityCapability extends Capability
attractors: Map<string, Attractor>
addAttractor(a: Attractor): void
removeAttractor(id: string): void
at(host: PhysicsHost, p: Vec3, ctx?: ScopeContext): Vec3Gravity 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