From c225ee696a4280097005d9ddd3578427fbdbcc7f Mon Sep 17 00:00:00 2001 From: Moonlit Productions Date: Tue, 11 Nov 2025 13:47:58 -0500 Subject: [PATCH] Re-added keyboard controls alongside joysticks --- script.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/script.js b/script.js index c6aef35..ee2f80a 100644 --- a/script.js +++ b/script.js @@ -45,6 +45,7 @@ class Joystick { deactivate() { this.active = false; + this.reset(); } touchInRange(x, y) { @@ -1018,13 +1019,20 @@ function animate() { if (isManualInputMode) { const maxSpeed = parseFloat(keyboardMaxSpeed.value); const maxRotation = parseFloat(keyboardMaxRotation.value); - // xSpeed = manualInputVelX; - // ySpeed = -manualInputVelY; // Negative because canvas Y axis is inverted - // turnSpeed = manualInputOmega; - xSpeed = leftJoystick.getX() * maxSpeed; - ySpeed = -leftJoystick.getY() * maxSpeed; - turnSpeed = rightJoystick.getX() * maxRotation; + // Combine keyboard and joystick inputs + const keyboardX = manualInputVelX; + const keyboardY = -manualInputVelY; // Negative because canvas Y axis is inverted + const keyboardOmega = manualInputOmega; + + const joystickX = leftJoystick.getX() * maxSpeed; + const joystickY = -leftJoystick.getY() * maxSpeed; + const joystickOmega = rightJoystick.getX() * maxRotation; + + // Use joystick if active, otherwise use keyboard + xSpeed = leftJoystick.active ? joystickX : keyboardX; + ySpeed = leftJoystick.active ? joystickY : keyboardY; + turnSpeed = rightJoystick.active ? joystickOmega : keyboardOmega; } else { xSpeed = parseFloat(vxSlider.value); ySpeed = -parseFloat(vySlider.value);