b3d-input-focus
Focus manager that wires input to the active controllable entity and handles enter/exit vehicle mechanics.
How It Works
- Finds the
player: trueentity among its children, and wires keyboard, mouse, gamepads and XR controllers to it (through agameControllerit builds, or one you nested to set its options) - 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 { assetUrl, b3d, b3dBiped, b3dCar, b3dLibrary, inputFocus } from 'tosijs-3d'
document.body.append(
b3d({},
b3dLibrary({ url: assetUrl('tonio/vehicles/cars.glb'), type: 'cars' }),
inputFocus(
b3dBiped({ url: '/character.glb', player: true, cameraType: 'follow' }),
b3dCar({ library: 'cars', meshName: 'Sedan', scale: 2, enterable: true, x: 5 })
)
)
)