InputController
new InputController(options : Object)Create a new InputController.
Constructor Parameters
optionsoptionalObjectConfiguration options
Default is
Default is
{}.elementoptionalEventTargetElement to attach events to (virtualElement for offscreen, window for main thread)dispatcheroptionalObjectDispatcher with .on()/.off() for forwarded events (alternative to element)enableEditorKeysoptionalbooleanEnable editor/debug keys (., ,, /)
Default istrue.enableCameraToggleoptionalbooleanEnable camera mode toggle (V key)
Default istrue.keyConfigoptionalArrayCustom key configuration (defaults to standard game controls)onToggleCameraoptionalfunctionCallback when camera toggle key is pressedonTogglePauseoptionalfunctionCallback when pause key is pressedonToggleEditoroptionalfunctionCallback when editor toggle key is pressedonToggleOrbitoptionalfunctionCallback when orbit toggle key is pressed
Methods
releaseAllKeys#
releaseAllKeys()Release all pressed keys and reset input state.
isPressed#
isPressed(action : string) : booleanCheck if a specific action key is currently pressed.
Parameters
actionstringAction name (forward, backward, left, right, jump)
Returns
boolean — Whether the action key is pressedgetMovementState#
getMovementState() : ObjectGet current movement input state.
Returns
ObjectgetInput#
getInput() : ObjectGet current input state formatted for PhysicsController.applyInput().
Jump uses edge detection for bhop support - jumpPressed is only true on the frame the key goes down, not while held. This prevents multiple physics steps from seeing the same jump input.
Returns
Object — Input state objectgetMovementInput#
getMovementInput() : ObjectGet current movement input as a normalized vector.
Returns
Object — Normalized input vectorsetInputState#
setInputState(state : Object)Set input state programmatically (for gamepad or touch controls).
Parameters
stateObjectInput state to set
forwardoptionalbooleanForward statebackwardoptionalbooleanBackward stateleftoptionalbooleanLeft staterightoptionalbooleanRight statejumpoptionalbooleanJump state
setAnalogInput#
setAnalogInput(x : number, y : number, jump : boolean, deadzone : number)Set input from analog values (for gamepad sticks).
Parameters
xnumberX axis value (-1 to 1)
ynumberY axis value (-1 to 1)
jumpoptionalbooleanJump button state
Default is
Default is
false.deadzoneoptionalnumberDeadzone threshold
Default is
Default is
0.2.dispose#
dispose()Dispose and clean up all event listeners. Call this when the controller is no longer needed.