Gravity2D

View source

ExtendsVector2

Stores the world’s 2D gravity acceleration as a mutable Vector2 resource.

A directly constructed Gravity2D starts at (0, 0). Gravity2DPlugin installs the resource with a default value of (0, -980), or with the configured acceleration supplied to the plugin. The resource can be read or replaced through the world’s resource API.

Examples

import { Gravity2D } from '@wimaengine/gravity'
import { World } from '@wimaengine/ecs'

const world = new World()
world.setResource(new Gravity2D(0, -9.8))

function readGravity(world) {
  const gravity = world.getResource(Gravity2D)
  return { x: gravity.x, y: gravity.y }
}

readGravity(world) // { x: 0, y: -9.8 }

Constructor


Methods


staticserialize(value: Gravity2D): Vector2Like

View source

Parameters

NameDescriptionDefault
value——
  • @inheritDoc