PhysicsController
new PhysicsController(physicsAPI : Physics, options : Object)PhysicsController - Main Thread Physics Orchestrator
High-level controller that manages physics entity access, interpolation, and input routing. This is the primary class for integrating physics into your render loop.
Features
- EntityProxy access for reading physics state with interpolation
- Automatic input handling from keyboard/gamepad
- Frame timing and interpolation alpha calculation
- Camera mode and offset control
Key Responsibilities
| Responsibility | Method |
|---|---|
| Entity access | getDynamic(), getKinematic() → EntityProxy |
| Frame updates | update() |
| Input routing | applyInput() (auto or manual) |
| Camera control | setCameraMode(), setCameraDrag() |
| Lifecycle | pause(), resume(), dispose() |
Constructor Parameters
Initialized Physics instance
optionsoptionalObjectConfiguration options
Default is
Default is
{}.enableInputoptionalbooleanEnable automatic input handling
Default istrue.playerBodyIndexoptionalnumberBody index to apply input to
Default is0.inputOptionsoptionalObjectOptions to pass to InputController
Default is{}.
Example
const physics = new Physics();
await physics.init();
await physics.start();
// Input is handled automatically
const controller = new PhysicsController( physics );
// In render loop
function animate() {
controller.update( delta );
renderer.render( scene, camera );
}