Skip to content

Commit 4ae20d8

Browse files
committed
fix camera movement
1 parent 25a7f83 commit 4ae20d8

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

packages/@dcl/inspector/src/lib/babylon/decentraland/camera.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,25 @@ export class CameraManager {
163163
return false
164164
}
165165

166+
let isAltKeyDown = false
166167
scene.onPreKeyboardObservable.add((ev) => {
167-
const isAltKeyDown = ev.type === BABYLON.KeyboardEventTypes.KEYDOWN && ev.event.inputIndex === Keys.KEY_ALT
168+
const oldAltKeyState = isAltKeyDown
169+
if (ev.type === BABYLON.KeyboardEventTypes.KEYDOWN && ev.event.inputIndex === Keys.KEY_ALT) {
170+
isAltKeyDown = true
171+
}
172+
173+
if (ev.type === BABYLON.KeyboardEventTypes.KEYUP && ev.event.inputIndex === Keys.KEY_ALT) {
174+
isAltKeyDown = false
175+
}
168176

169177
if (isAltKeyDown) {
170178
mouseInput.buttons = [LEFT_BUTTON, RIGHT_BUTTON] // move camera with left/right mouse buttons
171179
} else {
172180
mouseInput.buttons = [RIGHT_BUTTON] // move camera with right mouse button only
173-
// reattach control to avoid camera sticking to the pointer bug...
174-
this.reattachControl()
181+
if (oldAltKeyState) {
182+
// reattach control to avoid camera sticking to the pointer bug...
183+
this.reattachControl()
184+
}
175185
}
176186
})
177187

packages/@dcl/inspector/src/lib/babylon/setup/input.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export function initKeyboard(canvas: HTMLCanvasElement, scene: BABYLON.Scene) {
1414
canvas.addEventListener('keydown', (e) => {
1515
keyState[Keys.KEY_SHIFT] = e.shiftKey
1616
keyState[Keys.KEY_CTRL] = e.ctrlKey
17+
keyState[Keys.KEY_ALT] = e.altKey
1718
keyState[e.keyCode] = true
1819
if (e.shiftKey) {
1920
isSnapEnabled = snapManager.toggle()
@@ -29,13 +30,15 @@ export function initKeyboard(canvas: HTMLCanvasElement, scene: BABYLON.Scene) {
2930

3031
keyState[Keys.KEY_SHIFT] = e.shiftKey
3132
keyState[Keys.KEY_CTRL] = e.ctrlKey
33+
keyState[Keys.KEY_ALT] = e.altKey
3234
keyState[e.keyCode] = false
3335
})
3436

3537
// When the canvas lost the focus, clear the special keys state
3638
canvas.addEventListener('blur', () => {
3739
keyState[Keys.KEY_SHIFT] = false
3840
keyState[Keys.KEY_CTRL] = false
41+
keyState[Keys.KEY_ALT] = false
3942
})
4043

4144
// Event to store the ctrlKey when the canvas has lost the focus

0 commit comments

Comments
 (0)