Default keyboard control arrowkeys for UniversalCamera/FreeCamera?

I am kind confused how to use the default keyboard keys to move UniversalCamera,
my question based on this PG

in this PG, by presssing key ArrowRight, ArrowLeft, ArrowUp, ArrowDown moves camera.
no special code need to have this functionality..

But cannot have the same functionality in my App using UniversalCamera or FreeCamera.
my code is this

import { UniversalCamera, ArcRotateCamera, HemisphericLight, PointLight, GlowLayer, Color3, Vector3, TransformNode} from '@babylonjs/core';
	//universalcamera
	this.camera = new UniversalCamera('universal-camera', new Vector3(0, 0, (1500 * 3)), scene);
	
	this.camera.maxZ =  20000000;
	this.camera.minZ = 0.5;
	this.camera.fov = 0.5; 
	this.camera.inertia = 0.9;
	this.camera.angularSensibility = 1500;
	this.camera.speed = 0.2;
	this.camera.inputs.addMouseWheel();
	this.camera.attachControl(canvas, true);

with this code cannot move camera with arrowkeys!!

log for UniversalCamera (firefox)

Object { attachedToElement: true, attached: {…}, camera: {…}, checkInputs: _addCheckInputs(), _mouseInput: {…}, _mouseWheelInput: {…}, noPreventDefault: true }
​
_mouseInput: Object { touchEnabled: false, angularSensibility: 1500, _allowCameraRotation: true, … }
​
_mouseWheelInput: Object { wheelPrecisionX: 0.6, wheelPrecisionY: 0.6, wheelPrecisionZ: 0.6, … }
​
attached: Object { keyboard: {…}, mouse: {…}, touch: {…}, … }
​​
gamepad: Object { gamepadAngularSensibility: 200, gamepadMoveSensibility: 40, deadzoneDelta: 0.1, … }
​​
keyboard: Object { keysUp: (1) […], keysUpward: (1) […], rotationSpeed: 0.5, … }
​​​
_engine: Object { _colorWrite: true, _colorWriteChanged: false, _badOS: false, … }
​​​
_keys: Array []
​​​
_onCanvasBlurObserver: Object { mask: -1, _willBeUnregistered: false, unregisterOnNextCall: false, … }
​​​
_onKeyboardObserver: Object { mask: -1, _willBeUnregistered: false, unregisterOnNextCall: false, … }
​​​
_scene: Object { _isScene: true, _blockEntityCollection: false, autoClear: true, … }
​​​
camera: Object { _isDirty: false, _nodeDataStorage: {…}, state: "", … }
​​​
keysDown: Array [ 40 ]
​​​
keysDownward: Array [ 34 ]
​​​
keysLeft: Array [ 37 ]
​​​
keysRight: Array [ 39 ]
​​​
keysRotateDown: Array []
​​​
keysRotateLeft: Array []
​​​
keysRotateRight: Array []
​​​
keysRotateUp: Array []
​​​
keysUp: Array [ 38 ]
​​​
keysUpward: Array [ 33 ]
​​​
rotationSpeed: 0.5
​​​
<prototype>: Object { … }
​​
mouse: Object { touchEnabled: false, angularSensibility: 1500, _allowCameraRotation: true, … }
​​
mousewheel: Object { wheelPrecisionX: 0.6, wheelPrecisionY: 0.6, wheelPrecisionZ: 0.6, … }
​​
touch: Object { allowMouse: false, touchAngularSensibility: 200000, touchMoveSensibility: 250, … }
​​
<prototype>: Object { … }
​
attachedToElement: true
​
camera: Object { _isDirty: false, _nodeDataStorage: {…}, state: "", … }
​
checkInputs: function _addCheckInputs()
​
noPreventDefault: true
​
<prototype>: Object { addDeviceOrientation: addDeviceOrientation(smoothFactor), addVirtualJoystick: addVirtualJoystick(), addGamepad: addGamepad(), … }

when i use ArcRotateCamera and press key ArrowRight, ArrowLeft, ArrowUp, ArrowDown moves camera.

log for ArcRotateCamera (firefox)

Object { attachedToElement: true, attached: {…}, camera: {…}, checkInputs: _addCheckInputs(), noPreventDefault: true }
​
attached: Object { keyboard: {…}, mousewheel: {…}, pointers: {…} }
​​
keyboard: Object { panningSensibility: 50, zoomingSensibility: 25, useAltToZoom: true, … }
​​
mousewheel: Object { wheelPrecision: 0.1, zoomToMouseLocation: false, wheelDeltaPercentage: 0.002, … }
​​
pointers: Object { _currentMousePointerIdDown: -1, angularSensibilityX: 3000, angularSensibilityY: 3000, … }
​​
<prototype>: Object { … }
​
attachedToElement: true
​
camera: Object { _isDirty: false, _nodeDataStorage: {…}, state: "", … }
​
checkInputs: function _addCheckInputs()
​
noPreventDefault: true
​
<prototype>: Object { addVRDeviceOrientation: addVRDeviceOrientation(), addGamepad: addGamepad(), … }

what i am missing here?
why cannot use the default arrowkeys??

Well i think this is a bug,
so please any administration to move this topic to Bugs..

i use UniversalCamera and ArcRotateCamera.

with ArcRotateCamera i have no problem

with UniversalCamera i can move game with mouse and mouse wheel
but i cannot move game with arrowKeys as they defined in FreeCameraKeyboardMoveInput.js

assume that is the default behavior and not needs any extra setup??

if not, then ignore everything and please point me to the correct direction!!

My game logs:

BJS - [11:54:57]: Babylon.js v8.30.2 - WebGL2 logger.ts:107:30
load _universalCamera Appcamera.js:140:11
FreeCamera called freeCamera.ts:22:5
FreeCameraInputsManager called freeCameraInputsManager.ts:15:5
FreeCameraKeyboardMoveInput called freeCameraKeyboardMoveInput.ts:23:5
FreeCameraMouseWheelInput called freeCameraMouseWheelInput.ts:388:2
attachControl called freeCameraKeyboardMoveInput.ts:101:9
Panels loaded
Robot started

Game build > Center of world, First object diameter > 18720 pos = {X: 0 Y: 0 Z: 0}
Last object diameter > 273.24 pos = {X: 2965737.5999999996 Y: 180 Z: 0}
Last object parent > Name: obj50, isInstance: NO, # of submeshes: 1, n vertices: 133903, parent: obj50_plane pos = {X: 273.5179339500922 Y: 0 Z: 0}

Distance between First object > Last object = 2965737.6054623844
Distance Camera to Last object = 2966269.288189081

Game Init > wait for actions

Log for First time that i press key ArrowUp:

FreeCameraKeyboardMoveInput > attachControl > this._onKeyboardObserver evt > keydown { target: canvas#renderCanvas, key: "ArrowUp", charCode: 0, keyCode: 38 } chunk-QPPDLDM3.js:16822:15

key pressed =  ArrowUp index.js:367:25

checkInputs() > keysUp = 38 chunk-QPPDLDM3.js:16878:19

camera._localDirection for keyUp > 
Object { _isDirty: true, _x: 0, _y: 0, _z: 0.01065645344380583 }
	_isDirty: true
	_x: 0
	_y: 0
	_z: 0.010965400129498294
	<prototype>: Object { … } chunk-QPPDLDM3.js:16880:19
	
checkInputs() > keysUp = 38 chunk-QPPDLDM3.js:16878:19
camera._localDirection for keyUp >  
Object { _isDirty: true, _x: 0, _y: 0, _z: 0.010327955589886497 }
	_isDirty: true
	_x: 0
	_y: 0
	_z: 0.010965400129498294
	<prototype>: Object { … }chunk-QPPDLDM3.js:16880:19
	
checkInputs() > keysUp = 38 chunk-QPPDLDM3.js:16878:19
camera._localDirection for keyUp >  
Object { _isDirty: true, _x: 0, _y: 0, _z: 0.010965400129498294 }
	_isDirty: true
	_x: 0
	_y: 0
	_z: 0.010965400129498294
	<prototype>: Object { … } chunk-QPPDLDM3.js:16880:19
	
FreeCameraKeyboardMoveInput > attachControl > this._onKeyboardObserver evt >  keyup { target: canvas#renderCanvas, key: "ArrowUp", charCode: 0, keyCode: 38 }

Log after I move mouse a bit and then press ArrowUp:

FreeCameraKeyboardMoveInput > attachControl > this._onKeyboardObserver evt >  keydown { target: canvas#renderCanvas, key: "ArrowUp", charCode: 0, keyCode: 38 } chunk-QPPDLDM3.js:16822:15

key pressed =  ArrowUp index.js:367:25

checkInputs() > keysUp = 38 chunk-QPPDLDM3.js:16878:19
camera._localDirection for keyUp >  
Object { _isDirty: true, _x: 0, _y: 0, _z: 0.010965400129498275 }
	_isDirty: true
	_x: 0
	_y: 0
	_z: 0.010656453443805813
	<prototype>: Object { … } chunk-QPPDLDM3.js:16880:19

checkInputs() > keysUp = 38 chunk-QPPDLDM3.js:16878:19
camera._localDirection for keyUp >  
Object { _isDirty: true, _x: 0, _y: 0, _z: 0.010338278386656102 }
	_isDirty: true
	_x: 0
	_y: 0
	_z: 0.010656453443805813
	<prototype>: Object { … } chunk-QPPDLDM3.js:16880:19

checkInputs() > keysUp = 38 chunk-QPPDLDM3.js:16878:19
camera._localDirection for keyUp >  
Object { _isDirty: true, _x: 0, _y: 0, _z: 0.01032795558988648 }
	_isDirty: true
	_x: 0
	_y: 0
	_z: 0.010656453443805813
	<prototype>: Object { … } chunk-QPPDLDM3.js:16880:19
	
checkInputs() > keysUp = 38 chunk-QPPDLDM3.js:16878:19
camera._localDirection for keyUp >  
	Object { _isDirty: true, _x: 0, _y: 0, _z: 0.010656453443805813 }
	_isDirty: true
	_x: 0
	_y: 0
	_z: 0.010656453443805813
	<prototype>: Object { … } chunk-QPPDLDM3.js:16880:19

checkInputs() > keysUp = 38 chunk-QPPDLDM3.js:16878:19
camera._localDirection for keyUp >  
Object { _isDirty: true, _x: 0, _y: 0, _z: 0.010656453443805813 }
	_isDirty: true
	_x: 0
	_y: 0
	_z: 0.010656453443805813
	<prototype>: Object { … } chunk-QPPDLDM3.js:16880:19

FreeCameraKeyboardMoveInput > attachControl > this._onKeyboardObserver evt >  
keyup { target: canvas#renderCanvas, key: "ArrowUp", charCode: 0, keyCode: 38 } chunk-QPPDLDM3.js:16822:15

so in FreeCameraKeyboardMoveInput.js > checkInputs() > camera._localDirection is changed but not executed!

is this a bug?

OK, seems like there no BUG as i say, something wrong is with my code… :face_with_monocle:
although cannot find where the heck is the problem..

Sorry for the false alert :slightly_smiling_face:

2 Likes