Update index.html
Browse files- index.html +75 -66
index.html
CHANGED
|
@@ -78,8 +78,8 @@
|
|
| 78 |
|
| 79 |
#joystickHandle {
|
| 80 |
position: absolute;
|
| 81 |
-
width:
|
| 82 |
-
height:
|
| 83 |
background: radial-gradient(circle, rgba(0, 150, 255, 0.8), rgba(0, 100, 200, 0.6));
|
| 84 |
border: 3px solid rgba(255, 255, 255, 0.5);
|
| 85 |
border-radius: 50%;
|
|
@@ -398,7 +398,7 @@
|
|
| 398 |
|
| 399 |
// Forward/backward: negative dy = forward, positive dy = backward
|
| 400 |
moveForwardBack = -(dy / maxDistance);
|
| 401 |
-
// Left/right: negative dx = left, positive dx = right
|
| 402 |
moveSideways = dx / maxDistance;
|
| 403 |
} else {
|
| 404 |
joystickHandle.style.transform = 'translate(-50%, -50%)';
|
|
@@ -418,11 +418,13 @@
|
|
| 418 |
|
| 419 |
document.getElementById('upBtn').addEventListener('touchstart', (e) => {
|
| 420 |
e.preventDefault();
|
|
|
|
| 421 |
playerPos.y += 0.5;
|
| 422 |
});
|
| 423 |
|
| 424 |
document.getElementById('downBtn').addEventListener('touchstart', (e) => {
|
| 425 |
e.preventDefault();
|
|
|
|
| 426 |
playerPos.y = Math.max(0.5, playerPos.y - 0.5);
|
| 427 |
});
|
| 428 |
|
|
@@ -430,26 +432,14 @@
|
|
| 430 |
let lastLookPos = { x: 0, y: 0 };
|
| 431 |
|
| 432 |
document.addEventListener('touchstart', (e) => {
|
| 433 |
-
if (joystickActive) return;
|
| 434 |
-
|
| 435 |
const touch = e.touches[0];
|
| 436 |
|
| 437 |
-
// Check if touching joystick area
|
| 438 |
const joystickRect = joystick.getBoundingClientRect();
|
| 439 |
-
if (touch.clientX >= joystickRect.left -
|
| 440 |
-
touch.clientX <= joystickRect.right +
|
| 441 |
-
touch.clientY >= joystickRect.top -
|
| 442 |
-
touch.clientY <= joystickRect.bottom +
|
| 443 |
-
return;
|
| 444 |
-
}
|
| 445 |
-
|
| 446 |
-
// Check if touching buttons area
|
| 447 |
-
const buttonsArea = document.querySelector('.button-group');
|
| 448 |
-
const buttonsRect = buttonsArea.getBoundingClientRect();
|
| 449 |
-
if (touch.clientX >= buttonsRect.left - 20 &&
|
| 450 |
-
touch.clientX <= buttonsRect.right + 20 &&
|
| 451 |
-
touch.clientY >= buttonsRect.top - 20 &&
|
| 452 |
-
touch.clientY <= buttonsRect.bottom + 20) {
|
| 453 |
return;
|
| 454 |
}
|
| 455 |
|
|
@@ -462,20 +452,24 @@
|
|
| 462 |
return;
|
| 463 |
}
|
| 464 |
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
|
|
|
|
|
|
|
|
|
| 468 |
});
|
| 469 |
|
| 470 |
document.addEventListener('touchmove', (e) => {
|
| 471 |
-
if (!isLooking
|
| 472 |
e.preventDefault();
|
| 473 |
const touch = e.touches[0];
|
| 474 |
const deltaX = touch.clientX - lastLookPos.x;
|
| 475 |
const deltaY = touch.clientY - lastLookPos.y;
|
| 476 |
|
| 477 |
-
|
| 478 |
-
cameraRotation.
|
|
|
|
| 479 |
cameraRotation.x = Math.max(-Math.PI / 2.5, Math.min(Math.PI / 2.5, cameraRotation.x));
|
| 480 |
|
| 481 |
lastLookPos = { x: touch.clientX, y: touch.clientY };
|
|
@@ -498,64 +492,81 @@
|
|
| 498 |
function checkCollisions(newPos) {
|
| 499 |
if (!garage) return newPos;
|
| 500 |
|
| 501 |
-
const playerRadius = 0.
|
| 502 |
-
const minGroundClearance = 0.
|
| 503 |
|
| 504 |
-
|
| 505 |
-
|
|
|
|
| 506 |
}
|
| 507 |
|
|
|
|
| 508 |
const testPoints = [
|
| 509 |
new THREE.Vector3(newPos.x, newPos.y, newPos.z),
|
|
|
|
| 510 |
new THREE.Vector3(newPos.x + playerRadius, newPos.y, newPos.z),
|
| 511 |
new THREE.Vector3(newPos.x - playerRadius, newPos.y, newPos.z),
|
| 512 |
new THREE.Vector3(newPos.x, newPos.y, newPos.z + playerRadius),
|
| 513 |
new THREE.Vector3(newPos.x, newPos.y, newPos.z - playerRadius),
|
| 514 |
];
|
| 515 |
|
|
|
|
|
|
|
| 516 |
for (const point of testPoints) {
|
| 517 |
-
let hasCollision = false;
|
| 518 |
-
|
| 519 |
garage.traverse((child) => {
|
| 520 |
if (child.geometry && child.userData.isCollider) {
|
| 521 |
const box = new THREE.Box3().setFromObject(child);
|
| 522 |
|
| 523 |
-
|
|
|
|
| 524 |
hasCollision = true;
|
| 525 |
}
|
| 526 |
}
|
| 527 |
});
|
|
|
|
|
|
|
|
|
|
| 528 |
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 536 |
garage.traverse((child) => {
|
| 537 |
if (child.geometry && child.userData.isCollider) {
|
| 538 |
const box = new THREE.Box3().setFromObject(child);
|
| 539 |
-
if (box.distanceToPoint(
|
| 540 |
canSlideX = false;
|
| 541 |
}
|
| 542 |
}
|
| 543 |
});
|
| 544 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 545 |
garage.traverse((child) => {
|
| 546 |
if (child.geometry && child.userData.isCollider) {
|
| 547 |
const box = new THREE.Box3().setFromObject(child);
|
| 548 |
-
if (box.distanceToPoint(
|
| 549 |
canSlideZ = false;
|
| 550 |
}
|
| 551 |
}
|
| 552 |
});
|
| 553 |
-
|
| 554 |
-
if (canSlideX && !canSlideZ) return slideX;
|
| 555 |
-
if (canSlideZ && !canSlideX) return slideZ;
|
| 556 |
-
|
| 557 |
-
return playerPos;
|
| 558 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 559 |
}
|
| 560 |
|
| 561 |
return newPos;
|
|
@@ -564,24 +575,22 @@
|
|
| 564 |
function animate() {
|
| 565 |
requestAnimationFrame(animate);
|
| 566 |
|
| 567 |
-
// Calculate movement based on camera direction
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
playerPos = checkCollisions(newPos);
|
| 584 |
-
}
|
| 585 |
|
| 586 |
playerCube.position.set(playerPos.x, playerPos.y, playerPos.z);
|
| 587 |
|
|
|
|
| 78 |
|
| 79 |
#joystickHandle {
|
| 80 |
position: absolute;
|
| 81 |
+
width: 50px;
|
| 82 |
+
height: 50px;
|
| 83 |
background: radial-gradient(circle, rgba(0, 150, 255, 0.8), rgba(0, 100, 200, 0.6));
|
| 84 |
border: 3px solid rgba(255, 255, 255, 0.5);
|
| 85 |
border-radius: 50%;
|
|
|
|
| 398 |
|
| 399 |
// Forward/backward: negative dy = forward, positive dy = backward
|
| 400 |
moveForwardBack = -(dy / maxDistance);
|
| 401 |
+
// Left/right: negative dx = left, positive dx = right (strafe movement)
|
| 402 |
moveSideways = dx / maxDistance;
|
| 403 |
} else {
|
| 404 |
joystickHandle.style.transform = 'translate(-50%, -50%)';
|
|
|
|
| 418 |
|
| 419 |
document.getElementById('upBtn').addEventListener('touchstart', (e) => {
|
| 420 |
e.preventDefault();
|
| 421 |
+
e.stopPropagation();
|
| 422 |
playerPos.y += 0.5;
|
| 423 |
});
|
| 424 |
|
| 425 |
document.getElementById('downBtn').addEventListener('touchstart', (e) => {
|
| 426 |
e.preventDefault();
|
| 427 |
+
e.stopPropagation();
|
| 428 |
playerPos.y = Math.max(0.5, playerPos.y - 0.5);
|
| 429 |
});
|
| 430 |
|
|
|
|
| 432 |
let lastLookPos = { x: 0, y: 0 };
|
| 433 |
|
| 434 |
document.addEventListener('touchstart', (e) => {
|
|
|
|
|
|
|
| 435 |
const touch = e.touches[0];
|
| 436 |
|
| 437 |
+
// Check if touching joystick area - completely block it
|
| 438 |
const joystickRect = joystick.getBoundingClientRect();
|
| 439 |
+
if (touch.clientX >= joystickRect.left - 30 &&
|
| 440 |
+
touch.clientX <= joystickRect.right + 30 &&
|
| 441 |
+
touch.clientY >= joystickRect.top - 30 &&
|
| 442 |
+
touch.clientY <= joystickRect.bottom + 30) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 443 |
return;
|
| 444 |
}
|
| 445 |
|
|
|
|
| 452 |
return;
|
| 453 |
}
|
| 454 |
|
| 455 |
+
// Allow looking in larger area - exclude only small button strip on right
|
| 456 |
+
if (touch.clientX < window.innerWidth * 0.85) {
|
| 457 |
+
isLooking = true;
|
| 458 |
+
lastLookPos = { x: touch.clientX, y: touch.clientY };
|
| 459 |
+
e.preventDefault();
|
| 460 |
+
}
|
| 461 |
});
|
| 462 |
|
| 463 |
document.addEventListener('touchmove', (e) => {
|
| 464 |
+
if (!isLooking) return;
|
| 465 |
e.preventDefault();
|
| 466 |
const touch = e.touches[0];
|
| 467 |
const deltaX = touch.clientX - lastLookPos.x;
|
| 468 |
const deltaY = touch.clientY - lastLookPos.y;
|
| 469 |
|
| 470 |
+
// Increased sensitivity
|
| 471 |
+
cameraRotation.y -= deltaX * 0.004;
|
| 472 |
+
cameraRotation.x -= deltaY * 0.004;
|
| 473 |
cameraRotation.x = Math.max(-Math.PI / 2.5, Math.min(Math.PI / 2.5, cameraRotation.x));
|
| 474 |
|
| 475 |
lastLookPos = { x: touch.clientX, y: touch.clientY };
|
|
|
|
| 492 |
function checkCollisions(newPos) {
|
| 493 |
if (!garage) return newPos;
|
| 494 |
|
| 495 |
+
const playerRadius = 0.35;
|
| 496 |
+
const minGroundClearance = 0.1;
|
| 497 |
|
| 498 |
+
// Allow movement even when close to ground, just not below it
|
| 499 |
+
if (newPos.y < minGroundClearance) {
|
| 500 |
+
newPos.y = minGroundClearance;
|
| 501 |
}
|
| 502 |
|
| 503 |
+
// Check collision at multiple heights
|
| 504 |
const testPoints = [
|
| 505 |
new THREE.Vector3(newPos.x, newPos.y, newPos.z),
|
| 506 |
+
new THREE.Vector3(newPos.x, newPos.y + 0.5, newPos.z),
|
| 507 |
new THREE.Vector3(newPos.x + playerRadius, newPos.y, newPos.z),
|
| 508 |
new THREE.Vector3(newPos.x - playerRadius, newPos.y, newPos.z),
|
| 509 |
new THREE.Vector3(newPos.x, newPos.y, newPos.z + playerRadius),
|
| 510 |
new THREE.Vector3(newPos.x, newPos.y, newPos.z - playerRadius),
|
| 511 |
];
|
| 512 |
|
| 513 |
+
let hasCollision = false;
|
| 514 |
+
|
| 515 |
for (const point of testPoints) {
|
|
|
|
|
|
|
| 516 |
garage.traverse((child) => {
|
| 517 |
if (child.geometry && child.userData.isCollider) {
|
| 518 |
const box = new THREE.Box3().setFromObject(child);
|
| 519 |
|
| 520 |
+
// Smaller collision radius for smoother movement
|
| 521 |
+
if (box.distanceToPoint(point) < playerRadius * 0.3) {
|
| 522 |
hasCollision = true;
|
| 523 |
}
|
| 524 |
}
|
| 525 |
});
|
| 526 |
+
|
| 527 |
+
if (hasCollision) break;
|
| 528 |
+
}
|
| 529 |
|
| 530 |
+
if (hasCollision) {
|
| 531 |
+
// Try sliding along walls independently for X and Z
|
| 532 |
+
const slideX = { x: newPos.x, y: newPos.y, z: playerPos.z };
|
| 533 |
+
const slideZ = { x: playerPos.x, y: newPos.y, z: newPos.z };
|
| 534 |
+
|
| 535 |
+
let canSlideX = true;
|
| 536 |
+
let canSlideZ = true;
|
| 537 |
+
|
| 538 |
+
// Test X movement only
|
| 539 |
+
for (const point of testPoints) {
|
| 540 |
+
const testX = new THREE.Vector3(slideX.x, point.y, slideX.z);
|
| 541 |
garage.traverse((child) => {
|
| 542 |
if (child.geometry && child.userData.isCollider) {
|
| 543 |
const box = new THREE.Box3().setFromObject(child);
|
| 544 |
+
if (box.distanceToPoint(testX) < playerRadius * 0.3) {
|
| 545 |
canSlideX = false;
|
| 546 |
}
|
| 547 |
}
|
| 548 |
});
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
+
// Test Z movement only
|
| 552 |
+
for (const point of testPoints) {
|
| 553 |
+
const testZ = new THREE.Vector3(slideZ.x, point.y, slideZ.z);
|
| 554 |
garage.traverse((child) => {
|
| 555 |
if (child.geometry && child.userData.isCollider) {
|
| 556 |
const box = new THREE.Box3().setFromObject(child);
|
| 557 |
+
if (box.distanceToPoint(testZ) < playerRadius * 0.3) {
|
| 558 |
canSlideZ = false;
|
| 559 |
}
|
| 560 |
}
|
| 561 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 562 |
}
|
| 563 |
+
|
| 564 |
+
// Allow sliding along one axis
|
| 565 |
+
if (canSlideX && !canSlideZ) return slideX;
|
| 566 |
+
if (canSlideZ && !canSlideX) return slideZ;
|
| 567 |
+
|
| 568 |
+
// If both blocked, stay in place
|
| 569 |
+
return playerPos;
|
| 570 |
}
|
| 571 |
|
| 572 |
return newPos;
|
|
|
|
| 575 |
function animate() {
|
| 576 |
requestAnimationFrame(animate);
|
| 577 |
|
| 578 |
+
// Calculate movement based on camera direction (always, not just when joystick active)
|
| 579 |
+
// Forward/backward relative to camera
|
| 580 |
+
const forwardX = -Math.sin(cameraRotation.y) * moveForwardBack * moveSpeed;
|
| 581 |
+
const forwardZ = -Math.cos(cameraRotation.y) * moveForwardBack * moveSpeed;
|
| 582 |
+
|
| 583 |
+
// Left/right strafe relative to camera (perpendicular to forward)
|
| 584 |
+
const strafeX = -Math.sin(cameraRotation.y + Math.PI / 2) * moveSideways * moveSpeed;
|
| 585 |
+
const strafeZ = -Math.cos(cameraRotation.y + Math.PI / 2) * moveSideways * moveSpeed;
|
| 586 |
+
|
| 587 |
+
const newPos = {
|
| 588 |
+
x: playerPos.x + forwardX + strafeX,
|
| 589 |
+
y: playerPos.y,
|
| 590 |
+
z: playerPos.z + forwardZ + strafeZ
|
| 591 |
+
};
|
| 592 |
+
|
| 593 |
+
playerPos = checkCollisions(newPos);
|
|
|
|
|
|
|
| 594 |
|
| 595 |
playerCube.position.set(playerPos.x, playerPos.y, playerPos.z);
|
| 596 |
|