Physics2DPlugin

View source

ExtendsPlugin

Adds configurable 2D collision handling to an App.

The plugin combines collider-bound updates, broadphase candidate selection, narrowphase contact detection, and collision response. Applications can provide their own Broadphase2DPlugin and NarrowPhase2DPlugin instances; when omitted, the plugin creates a default broadphase using NaiveBroadphase2D and a default narrowphase plugin. Collider bounds are refreshed automatically by default; applications that maintain their own bounds can disable that behavior.

Examples

import { App } from '@wimaengine/app'
import { CorePlugin } from '@wimaengine/core'
import { HierarchyPlugin } from '@wimaengine/hierarchy'
import { MathPlugin } from '@wimaengine/math'
import { Physics2DPlugin } from '@wimaengine/physics'
import { ReflectPlugin } from '@wimaengine/reflect'
import { Transform2DPlugin } from '@wimaengine/transform'

new App()
  .registerPlugin(new ReflectPlugin())
  .registerPlugin(new CorePlugin())
  .registerPlugin(new MathPlugin())
  .registerPlugin(new HierarchyPlugin())
  .registerPlugin(new Transform2DPlugin())
  .registerPlugin(new Physics2DPlugin())
  .run()

Constructor


constructor(options?: Physics2DPluginOptions)

View source

Creates a 2D physics integration with optional plugin injection.

Omitted broadphase and narrowphase options create the default collision plugins. Supplied plugin instances are kept by reference and registered with the app when this plugin is registered. autoUpdateBounds defaults to true; set it to false when the application updates PhysicsHitbox bounds itself.

The integrator option defaults to EulerIntegrator2DPlugin and is retained for compatibility. It does not configure the collision handling performed by this plugin.

Parameters

NameDescriptionDefault
options?

Plugin configuration.

{}

Properties


Methods


register(app: App): void

View source

Registers the physics integration and its configured collision plugins with app.

During each update, colliders follow their associated transforms. When autoUpdateBounds is enabled, PhysicsHitbox bounds are refreshed automatically; otherwise the application must maintain them before collision detection runs. The configured Broadphase2DPlugin and NarrowPhase2DPlugin instances are registered so their collision data is available, and the resulting contacts are resolved for the update.

Parameters

NameDescriptionDefault
app

App to configure.

—