b3d-input-focus
Focus manager that wires input to the active controllable entity and handles enter/exit vehicle mechanics.
How It Works
- Discovers the
gameControllerandplayer: trueentity among its children - Routes the controller's input to whichever entity has focus
- On E press near an
enterablevehicle, switches focus (hides biped, drives vehicle) - On E press while in a vehicle, exits back to biped
When switching entities, the input mapping is swapped to match the entity type (e.g. bipedMapping for characters, aircraftMapping for aircraft).
Attributes
| Attribute | Default | Description |
|---|---|---|
enterDistance |
3 |
Max distance to enter a vehicle |
Usage
import { b3d, b3dBiped, b3dCar, gameController, inputFocus } from 'tosijs-3d'
document.body.append(
b3d({},
inputFocus(
gameController(),
b3dBiped({ url: '/character.glb', player: true, cameraType: 'follow' }),
b3dCar({ url: '/car.glb', enterable: true, x: 5 })
)
)
)