Compare commits
1 Commits
PWA
...
mobileFrie
| Author | SHA1 | Date | |
|---|---|---|---|
|
c225ee696a
|
20
script.js
20
script.js
@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user