constructor(options?: Gravity3DPluginOptions)
View sourceCreates a 3D gravity plugin.
The optional gravity value is a Vector3. When omitted, it
defaults to (0, -980, 0).
Class
ExtendsPlugin
Adds configurable 3D gravity to an App.
The plugin installs a Gravity3D resource initialized from the
configured Vector3, or (0, -980, 0) by default. It applies that
acceleration to eligible bodies as the app updates. The plugin depends on
CorePlugin, ReflectPlugin, MathPlugin,
Movable3DPlugin, and NarrowPhase2DPlugin.
Pass a Vector3 in options.gravity to choose a different
acceleration. The vector is copied into the installed resource.
import { App } from '@wimaengine/app'
import { CorePlugin } from '@wimaengine/core'
import { Gravity3DPlugin } from '@wimaengine/gravity'
import { MathPlugin, Vector3 } from '@wimaengine/math'
import { Movable3DPlugin } from '@wimaengine/movable'
import { NarrowPhase2DPlugin } from '@wimaengine/narrowphase'
import { ReflectPlugin } from '@wimaengine/reflect'
new App()
.registerPlugin(new ReflectPlugin())
.registerPlugin(new CorePlugin())
.registerPlugin(new MathPlugin())
.registerPlugin(new Movable3DPlugin())
.registerPlugin(new NarrowPhase2DPlugin())
.registerPlugin(new Gravity3DPlugin({
gravity: new Vector3(0, -9.8, 0)
}))
.run()constructor(options?: Gravity3DPluginOptions)Creates a 3D gravity plugin.
The optional gravity value is a Vector3. When omitted, it
defaults to (0, -980, 0).
Configured Vector3 gravity vector.
The vector is copied into the installed Gravity3D resource when
the plugin is registered, so the resource has its own value.
register(app: App): voidInstalls configured 3D gravity in an app.
The installed Gravity3D contains a copy of
Gravity3DPlugin#gravity. Its acceleration is added to
eligible bodies’ 3D acceleration values as the app updates.
requires(): TypeId[]Returns the plugin dependencies required by 3D gravity.
The returned IDs identify CorePlugin, ReflectPlugin,
MathPlugin, Movable3DPlugin, and
NarrowPhase2DPlugin. Register these plugins before this one;
registering Gravity3DPlugin does not install them automatically.