1 Commits

Author SHA1 Message Date
c225ee696a Re-added keyboard controls alongside joysticks 2025-11-11 13:47:58 -05:00

View File

@ -45,6 +45,7 @@ class Joystick {
deactivate() { deactivate() {
this.active = false; this.active = false;
this.reset();
} }
touchInRange(x, y) { touchInRange(x, y) {
@ -1018,13 +1019,20 @@ function animate() {
if (isManualInputMode) { if (isManualInputMode) {
const maxSpeed = parseFloat(keyboardMaxSpeed.value); const maxSpeed = parseFloat(keyboardMaxSpeed.value);
const maxRotation = parseFloat(keyboardMaxRotation.value); const maxRotation = parseFloat(keyboardMaxRotation.value);
// xSpeed = manualInputVelX;
// ySpeed = -manualInputVelY; // Negative because canvas Y axis is inverted
// turnSpeed = manualInputOmega;
xSpeed = leftJoystick.getX() * maxSpeed; // Combine keyboard and joystick inputs
ySpeed = -leftJoystick.getY() * maxSpeed; const keyboardX = manualInputVelX;
turnSpeed = rightJoystick.getX() * maxRotation; 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 { } else {
xSpeed = parseFloat(vxSlider.value); xSpeed = parseFloat(vxSlider.value);
ySpeed = -parseFloat(vySlider.value); ySpeed = -parseFloat(vySlider.value);