Update index.html
Browse files- index.html +37 -9
index.html
CHANGED
|
@@ -263,6 +263,8 @@
|
|
| 263 |
<button class="control-btn" id="downBtn">↓ Down</button>
|
| 264 |
</div>
|
| 265 |
|
|
|
|
|
|
|
| 266 |
<div id="coordinates">
|
| 267 |
<div class="coord-label">POS</div>
|
| 268 |
<div>X: <span id="coordX">0.00</span></div>
|
|
@@ -290,6 +292,7 @@
|
|
| 290 |
<script type="module">
|
| 291 |
import * as THREE from 'three';
|
| 292 |
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
|
|
|
|
| 293 |
|
| 294 |
let scene, camera, renderer, playerCube, garage;
|
| 295 |
let playerPos = { x: 0, y: 1, z: 0 };
|
|
@@ -297,9 +300,15 @@
|
|
| 297 |
let moveForwardBack = 0;
|
| 298 |
let moveSpeed = 0.06;
|
| 299 |
let cameraRotation = { x: 0, y: 0 };
|
|
|
|
| 300 |
let spawnPoint = { x: -3.5719999999999996, y: 1, z: 0.20199999999999968 };
|
| 301 |
let joystickActive = false;
|
| 302 |
let lookTouchId = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
|
| 304 |
// Check orientation
|
| 305 |
function checkOrientation() {
|
|
@@ -441,8 +450,8 @@
|
|
| 441 |
joystickHandle.style.transform = `translate(calc(-50% + ${normalizedDx}px), calc(-50% + ${normalizedDy}px))`;
|
| 442 |
|
| 443 |
moveForwardBack = -(dy / maxDistance);
|
| 444 |
-
// FIXED:
|
| 445 |
-
moveSideways =
|
| 446 |
} else {
|
| 447 |
joystickHandle.style.transform = 'translate(-50%, -50%)';
|
| 448 |
moveForwardBack = 0;
|
|
@@ -471,16 +480,19 @@
|
|
| 471 |
if (notTouchingJoystick && notTouchingCoords && touch.clientX < window.innerWidth * 0.85) {
|
| 472 |
lookTouchId = touch.identifier;
|
| 473 |
lastLookPos = { x: touch.clientX, y: touch.clientY };
|
|
|
|
|
|
|
|
|
|
| 474 |
}
|
| 475 |
} else if (touch.identifier === lookTouchId) {
|
| 476 |
// Update existing look touch
|
| 477 |
const deltaX = touch.clientX - lastLookPos.x;
|
| 478 |
const deltaY = touch.clientY - lastLookPos.y;
|
| 479 |
|
| 480 |
-
//
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
|
| 485 |
lastLookPos = { x: touch.clientX, y: touch.clientY };
|
| 486 |
}
|
|
@@ -598,15 +610,31 @@
|
|
| 598 |
|
| 599 |
function animate() {
|
| 600 |
requestAnimationFrame(animate);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 601 |
|
| 602 |
-
// Calculate movement based on camera direction
|
| 603 |
// Forward/backward relative to camera
|
| 604 |
const forwardX = -Math.sin(cameraRotation.y) * moveForwardBack * moveSpeed;
|
| 605 |
const forwardZ = -Math.cos(cameraRotation.y) * moveForwardBack * moveSpeed;
|
| 606 |
|
| 607 |
// Left/right strafe relative to camera (perpendicular to forward)
|
| 608 |
-
|
| 609 |
-
const
|
|
|
|
| 610 |
|
| 611 |
const newPos = {
|
| 612 |
x: playerPos.x + forwardX + strafeX,
|
|
|
|
| 263 |
<button class="control-btn" id="downBtn">↓ Down</button>
|
| 264 |
</div>
|
| 265 |
|
| 266 |
+
<div id="fps">FPS: 0</div>
|
| 267 |
+
|
| 268 |
<div id="coordinates">
|
| 269 |
<div class="coord-label">POS</div>
|
| 270 |
<div>X: <span id="coordX">0.00</span></div>
|
|
|
|
| 292 |
<script type="module">
|
| 293 |
import * as THREE from 'three';
|
| 294 |
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
|
| 295 |
+
import { FBXLoader } from 'three/addons/loaders/FBXLoader.js';
|
| 296 |
|
| 297 |
let scene, camera, renderer, playerCube, garage;
|
| 298 |
let playerPos = { x: 0, y: 1, z: 0 };
|
|
|
|
| 300 |
let moveForwardBack = 0;
|
| 301 |
let moveSpeed = 0.06;
|
| 302 |
let cameraRotation = { x: 0, y: 0 };
|
| 303 |
+
let targetCameraRotation = { x: 0, y: 0 };
|
| 304 |
let spawnPoint = { x: -3.5719999999999996, y: 1, z: 0.20199999999999968 };
|
| 305 |
let joystickActive = false;
|
| 306 |
let lookTouchId = null;
|
| 307 |
+
|
| 308 |
+
// FPS counter
|
| 309 |
+
let lastTime = performance.now();
|
| 310 |
+
let frames = 0;
|
| 311 |
+
let fps = 0;
|
| 312 |
|
| 313 |
// Check orientation
|
| 314 |
function checkOrientation() {
|
|
|
|
| 450 |
joystickHandle.style.transform = `translate(calc(-50% + ${normalizedDx}px), calc(-50% + ${normalizedDy}px))`;
|
| 451 |
|
| 452 |
moveForwardBack = -(dy / maxDistance);
|
| 453 |
+
// FIXED AGAIN: Positive dx should move RIGHT
|
| 454 |
+
moveSideways = (dx / maxDistance);
|
| 455 |
} else {
|
| 456 |
joystickHandle.style.transform = 'translate(-50%, -50%)';
|
| 457 |
moveForwardBack = 0;
|
|
|
|
| 480 |
if (notTouchingJoystick && notTouchingCoords && touch.clientX < window.innerWidth * 0.85) {
|
| 481 |
lookTouchId = touch.identifier;
|
| 482 |
lastLookPos = { x: touch.clientX, y: touch.clientY };
|
| 483 |
+
// Initialize target rotation to current rotation
|
| 484 |
+
targetCameraRotation.x = cameraRotation.x;
|
| 485 |
+
targetCameraRotation.y = cameraRotation.y;
|
| 486 |
}
|
| 487 |
} else if (touch.identifier === lookTouchId) {
|
| 488 |
// Update existing look touch
|
| 489 |
const deltaX = touch.clientX - lastLookPos.x;
|
| 490 |
const deltaY = touch.clientY - lastLookPos.y;
|
| 491 |
|
| 492 |
+
// Update target rotation for smooth interpolation
|
| 493 |
+
targetCameraRotation.y -= deltaX * 0.012;
|
| 494 |
+
targetCameraRotation.x -= deltaY * 0.012;
|
| 495 |
+
targetCameraRotation.x = Math.max(-Math.PI / 2.5, Math.min(Math.PI / 2.5, targetCameraRotation.x));
|
| 496 |
|
| 497 |
lastLookPos = { x: touch.clientX, y: touch.clientY };
|
| 498 |
}
|
|
|
|
| 610 |
|
| 611 |
function animate() {
|
| 612 |
requestAnimationFrame(animate);
|
| 613 |
+
|
| 614 |
+
// FPS counter
|
| 615 |
+
frames++;
|
| 616 |
+
const currentTime = performance.now();
|
| 617 |
+
if (currentTime >= lastTime + 1000) {
|
| 618 |
+
fps = Math.round((frames * 1000) / (currentTime - lastTime));
|
| 619 |
+
document.getElementById('fps').textContent = `FPS: ${fps}`;
|
| 620 |
+
frames = 0;
|
| 621 |
+
lastTime = currentTime;
|
| 622 |
+
}
|
| 623 |
+
|
| 624 |
+
// Smooth camera interpolation for buttery smooth looking
|
| 625 |
+
const lerpFactor = 0.3;
|
| 626 |
+
cameraRotation.x += (targetCameraRotation.x - cameraRotation.x) * lerpFactor;
|
| 627 |
+
cameraRotation.y += (targetCameraRotation.y - cameraRotation.y) * lerpFactor;
|
| 628 |
|
| 629 |
+
// Calculate movement based on camera direction
|
| 630 |
// Forward/backward relative to camera
|
| 631 |
const forwardX = -Math.sin(cameraRotation.y) * moveForwardBack * moveSpeed;
|
| 632 |
const forwardZ = -Math.cos(cameraRotation.y) * moveForwardBack * moveSpeed;
|
| 633 |
|
| 634 |
// Left/right strafe relative to camera (perpendicular to forward)
|
| 635 |
+
// RIGHT: sin(angle + 90deg), cos(angle + 90deg)
|
| 636 |
+
const strafeX = Math.cos(cameraRotation.y) * moveSideways * moveSpeed;
|
| 637 |
+
const strafeZ = Math.sin(cameraRotation.y) * moveSideways * moveSpeed;
|
| 638 |
|
| 639 |
const newPos = {
|
| 640 |
x: playerPos.x + forwardX + strafeX,
|