applyGravity2D

View sourceapplyGravity2D(world: World): void

Applies the world’s 2D gravity to every eligible body.

Gravity2DPlugin registers this exact function directly in the repeating AppSchedule.Update schedule. The registration does not specify a system group, so the schedule’s default group is used. The plugin also installs the required Gravity2D resource.

The query requires Acceleration2D and PhysicsProperties, in that order. The system reads Gravity2D once from the world, then skips an entity when PhysicsProperties.invmass === 0. Every other matching entity receives the gravity vector through Vector2.add with the existing Acceleration2D passed as the output, so acceleration is mutated in place and the gravity resource is not changed. A world without Gravity2D fails during resource lookup.

Examples

import { AppSchedule } from '@wimaengine/core'
import { applyGravity2D } from '@wimaengine/gravity'

app.registerSystem({
  schedule: AppSchedule.Update,
  system: applyGravity2D
})
// Gravity2DPlugin already installs this system and its Gravity2D resource.

Parameters

NameDescriptionDefault
world

Update world containing Gravity2D and body components.

—

Throws

If the world does not contain Gravity2D.