Re-added keyboard controls alongside joysticks
This commit is contained in:
20
script.js
20
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);
|
||||
|
||||
Reference in New Issue
Block a user