Reaperxxxx commited on
Commit
8e9e979
·
verified ·
1 Parent(s): 66f228d

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +49 -148
index.html CHANGED
@@ -263,8 +263,6 @@
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,24 +290,16 @@
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, playerCharacter, otherCharacter, garage;
298
  let playerPos = { x: 0, y: 1, z: 0 };
299
  let moveSideways = 0;
300
  let moveForwardBack = 0;
301
- let moveSpeed = 0.03;
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
- let characterHeight = 1.7;
308
-
309
- let lastTime = performance.now();
310
- let frames = 0;
311
- let fps = 0;
312
-
313
  function checkOrientation() {
314
  const warning = document.getElementById('orientationWarning');
315
  if (window.innerHeight > window.innerWidth) {
@@ -322,25 +312,22 @@
322
  checkOrientation();
323
  window.addEventListener('resize', checkOrientation);
324
  window.addEventListener('orientationchange', checkOrientation);
325
-
326
  function init() {
327
  scene = new THREE.Scene();
328
  scene.background = new THREE.Color(0x1a1a2e);
329
  scene.fog = new THREE.Fog(0x1a1a2e, 5, 50);
330
-
331
  camera = new THREE.PerspectiveCamera(
332
  75,
333
  window.innerWidth / window.innerHeight,
334
  0.01,
335
  50
336
  );
337
-
338
  renderer = new THREE.WebGLRenderer({ antialias: true });
339
  renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
340
  renderer.setSize(window.innerWidth, window.innerHeight);
341
  renderer.shadowMap.enabled = true;
342
  document.body.appendChild(renderer.domElement);
343
-
344
  scene.add(new THREE.AmbientLight(0xffffff, 0.7));
345
 
346
  const dirLight1 = new THREE.DirectionalLight(0xffffff, 0.8);
@@ -356,6 +343,7 @@
356
  dirLight3.position.set(0, 20, -20);
357
  scene.add(dirLight3);
358
 
 
359
  const pointLight1 = new THREE.PointLight(0xffffff, 0.5, 50);
360
  pointLight1.position.set(10, 10, 10);
361
  scene.add(pointLight1);
@@ -367,68 +355,14 @@
367
  const pointLight3 = new THREE.PointLight(0xffffff, 0.4, 50);
368
  pointLight3.position.set(0, 5, 0);
369
  scene.add(pointLight3);
370
-
371
- const fbxLoader = new FBXLoader();
372
-
373
- fbxLoader.load('./character.fbx', (fbx) => {
374
- playerCharacter = fbx;
375
-
376
- const box = new THREE.Box3().setFromObject(playerCharacter);
377
- characterHeight = box.max.y - box.min.y;
378
-
379
- playerCharacter.scale.set(0.01, 0.01, 0.01);
380
- playerCharacter.position.set(playerPos.x, playerPos.y, playerPos.z);
381
- playerCharacter.castShadow = true;
382
- playerCharacter.receiveShadow = true;
383
-
384
- playerCharacter.traverse((child) => {
385
- if (child.isMesh) {
386
- child.castShadow = true;
387
- child.receiveShadow = true;
388
- }
389
- });
390
-
391
- scene.add(playerCharacter);
392
- console.log('✅ Player character loaded! Height:', characterHeight);
393
- }, undefined, (error) => {
394
- console.error('Error loading character:', error);
395
- const cubeGeometry = new THREE.BoxGeometry(0.5, 1.7, 0.5);
396
- const cubeMaterial = new THREE.MeshPhongMaterial({ color: 0xff0000 });
397
- playerCharacter = new THREE.Mesh(cubeGeometry, cubeMaterial);
398
- playerCharacter.position.set(playerPos.x, playerPos.y, playerPos.z);
399
- playerCharacter.castShadow = true;
400
- scene.add(playerCharacter);
401
- characterHeight = 1.7;
402
- console.log('⚠️ Player character load failed, using fallback cube');
403
- });
404
-
405
- fbxLoader.load('./character.fbx', (fbx) => {
406
- otherCharacter = fbx;
407
- otherCharacter.scale.set(0.01, 0.01, 0.01);
408
- otherCharacter.position.set(0.5351219542687073, 0.5, 3.6934482640617006);
409
- otherCharacter.castShadow = true;
410
- otherCharacter.receiveShadow = true;
411
-
412
- otherCharacter.traverse((child) => {
413
- if (child.isMesh) {
414
- child.castShadow = true;
415
- child.receiveShadow = true;
416
- }
417
- });
418
-
419
- scene.add(otherCharacter);
420
- console.log('✅ Other character loaded!');
421
- }, undefined, (error) => {
422
- console.error('Error loading other character:', error);
423
- const cubeGeometry = new THREE.BoxGeometry(0.5, 1.7, 0.5);
424
- const cubeMaterial = new THREE.MeshPhongMaterial({ color: 0x00ff00 });
425
- otherCharacter = new THREE.Mesh(cubeGeometry, cubeMaterial);
426
- otherCharacter.position.set(-3.5719999999999996, 0.5, 0.1934482640617006);
427
- otherCharacter.castShadow = true;
428
- scene.add(otherCharacter);
429
- console.log('⚠️ Other character load failed, using fallback cube');
430
- });
431
-
432
  const loader = new GLTFLoader();
433
  loader.load('./map.glb', (gltf) => {
434
  garage = gltf.scene;
@@ -450,36 +384,33 @@
450
  console.error('Error loading garage:', error);
451
  document.getElementById('loading').textContent = 'Error loading map.glb';
452
  });
453
-
454
  setupControls();
455
  animate();
456
-
457
  window.addEventListener('resize', () => {
458
  camera.aspect = window.innerWidth / window.innerHeight;
459
  camera.updateProjectionMatrix();
460
  renderer.setSize(window.innerWidth, window.innerHeight);
461
  });
462
  }
463
-
464
  function setupControls() {
465
  const joystick = document.getElementById('joystick');
466
  const joystickHandle = document.getElementById('joystickHandle');
467
  let joystickTouchId = null;
468
  let lastLookPos = { x: 0, y: 0 };
469
-
470
  joystick.addEventListener('touchstart', (e) => {
471
  joystickActive = true;
472
  joystickTouchId = e.touches[0].identifier;
473
  e.preventDefault();
474
  e.stopPropagation();
475
  });
476
-
477
  document.addEventListener('touchmove', (e) => {
478
  e.preventDefault();
479
 
 
480
  for (let i = 0; i < e.touches.length; i++) {
481
  const touch = e.touches[i];
482
 
 
483
  if (joystickTouchId !== null && touch.identifier === joystickTouchId) {
484
  const rect = joystick.getBoundingClientRect();
485
  const centerX = rect.left + rect.width / 2;
@@ -488,7 +419,6 @@
488
  const dy = touch.clientY - centerY;
489
  const distance = Math.sqrt(dx * dx + dy * dy);
490
  const maxDistance = 60;
491
-
492
  if (distance > 5) {
493
  const limitedDistance = Math.min(distance, maxDistance);
494
  const normalizedDx = (dx / distance) * limitedDistance;
@@ -497,7 +427,8 @@
497
  joystickHandle.style.transform = `translate(calc(-50% + ${normalizedDx}px), calc(-50% + ${normalizedDy}px))`;
498
 
499
  moveForwardBack = -(dy / maxDistance);
500
- moveSideways = (dx / maxDistance);
 
501
  } else {
502
  joystickHandle.style.transform = 'translate(-50%, -50%)';
503
  moveForwardBack = 0;
@@ -505,11 +436,14 @@
505
  }
506
  }
507
 
 
508
  if (touch.identifier !== joystickTouchId) {
509
  if (lookTouchId === null) {
 
510
  const joystickRect = joystick.getBoundingClientRect();
511
  const coordsRect = document.getElementById('coordinates').getBoundingClientRect();
512
 
 
513
  const notTouchingJoystick = !(touch.clientX >= joystickRect.left - 30 &&
514
  touch.clientX <= joystickRect.right + 30 &&
515
  touch.clientY >= joystickRect.top - 30 &&
@@ -523,26 +457,27 @@
523
  if (notTouchingJoystick && notTouchingCoords && touch.clientX < window.innerWidth * 0.85) {
524
  lookTouchId = touch.identifier;
525
  lastLookPos = { x: touch.clientX, y: touch.clientY };
526
- targetCameraRotation.x = cameraRotation.x;
527
- targetCameraRotation.y = cameraRotation.y;
528
  }
529
  } else if (touch.identifier === lookTouchId) {
 
530
  const deltaX = touch.clientX - lastLookPos.x;
531
  const deltaY = touch.clientY - lastLookPos.y;
532
 
533
- targetCameraRotation.y -= deltaX * 0.01;
534
- targetCameraRotation.x -= deltaY * 0.01;
535
- targetCameraRotation.x = Math.max(-Math.PI / 2.5, Math.min(Math.PI / 2.5, targetCameraRotation.x));
 
536
 
537
  lastLookPos = { x: touch.clientX, y: touch.clientY };
538
  }
539
  }
540
  }
541
  }, { passive: false });
542
-
543
  document.addEventListener('touchend', (e) => {
 
544
  const remainingTouchIds = Array.from(e.touches).map(t => t.identifier);
545
 
 
546
  if (joystickTouchId !== null && !remainingTouchIds.includes(joystickTouchId)) {
547
  joystickActive = false;
548
  joystickTouchId = null;
@@ -551,40 +486,41 @@
551
  moveSideways = 0;
552
  }
553
 
 
554
  if (lookTouchId !== null && !remainingTouchIds.includes(lookTouchId)) {
555
  lookTouchId = null;
556
  }
557
  });
558
-
559
  document.getElementById('upBtn').addEventListener('touchstart', (e) => {
560
  e.preventDefault();
561
  e.stopPropagation();
562
  playerPos.y += 0.5;
563
  });
564
-
565
  document.getElementById('downBtn').addEventListener('touchstart', (e) => {
566
  e.preventDefault();
567
  e.stopPropagation();
568
  playerPos.y = Math.max(0.5, playerPos.y - 0.5);
569
  });
 
 
 
570
  }
571
-
572
  function updateCoordinates() {
573
  document.getElementById('coordX').textContent = playerPos.x.toFixed(2);
574
  document.getElementById('coordY').textContent = playerPos.y.toFixed(2);
575
  document.getElementById('coordZ').textContent = playerPos.z.toFixed(2);
576
  }
577
-
578
  function checkCollisions(newPos) {
579
  if (!garage) return newPos;
580
-
581
- const playerRadius = 0.15;
 
582
  const raycaster = new THREE.Raycaster();
583
  const directions = [
584
- new THREE.Vector3(1, 0, 0),
585
- new THREE.Vector3(-1, 0, 0),
586
- new THREE.Vector3(0, 0, 1),
587
- new THREE.Vector3(0, 0, -1),
588
  ];
589
 
590
  const origin = new THREE.Vector3(newPos.x, newPos.y + 0.25, newPos.z);
@@ -604,9 +540,11 @@
604
  return newPos;
605
  }
606
 
 
607
  const tryX = { x: newPos.x, y: playerPos.y, z: playerPos.z };
608
  const tryZ = { x: playerPos.x, y: playerPos.y, z: newPos.z };
609
 
 
610
  let xBlocked = false;
611
  const originX = new THREE.Vector3(tryX.x, tryX.y + 0.25, tryX.z);
612
  for (const dir of directions) {
@@ -618,6 +556,7 @@
618
  }
619
  }
620
 
 
621
  let zBlocked = false;
622
  const originZ = new THREE.Vector3(tryZ.x, tryZ.y + 0.25, tryZ.z);
623
  for (const dir of directions) {
@@ -629,34 +568,22 @@
629
  }
630
  }
631
 
 
632
  if (!xBlocked) return tryX;
633
  if (!zBlocked) return tryZ;
634
 
635
  return playerPos;
636
  }
637
-
638
  function animate() {
639
  requestAnimationFrame(animate);
640
-
641
- frames++;
642
- const currentTime = performance.now();
643
- if (currentTime >= lastTime + 1000) {
644
- fps = Math.round((frames * 1000) / (currentTime - lastTime));
645
- document.getElementById('fps').textContent = `FPS: ${fps}`;
646
- frames = 0;
647
- lastTime = currentTime;
648
- }
649
-
650
- const lerpFactor = 0.25;
651
- cameraRotation.x += (targetCameraRotation.x - cameraRotation.x) * lerpFactor;
652
- cameraRotation.y += (targetCameraRotation.y - cameraRotation.y) * lerpFactor;
653
-
654
  const forwardX = -Math.sin(cameraRotation.y) * moveForwardBack * moveSpeed;
655
  const forwardZ = -Math.cos(cameraRotation.y) * moveForwardBack * moveSpeed;
656
 
657
- const strafeX = -Math.cos(cameraRotation.y) * moveSideways * moveSpeed;
658
- const strafeZ = -Math.sin(cameraRotation.y) * moveSideways * moveSpeed;
659
-
660
  const newPos = {
661
  x: playerPos.x + forwardX + strafeX,
662
  y: playerPos.y,
@@ -665,38 +592,15 @@
665
 
666
  playerPos = checkCollisions(newPos);
667
 
668
- if (playerCharacter) {
669
- playerCharacter.position.set(playerPos.x, playerPos.y, playerPos.z);
670
-
671
- if (moveForwardBack !== 0 || moveSideways !== 0) {
672
- const moveAngle = Math.atan2(moveSideways, -moveForwardBack);
673
- playerCharacter.rotation.y = cameraRotation.y + moveAngle;
674
- } else {
675
- playerCharacter.rotation.y = cameraRotation.y;
676
- }
677
- }
678
-
679
- const neckHeight = characterHeight * 0.85;
680
- const headForward = 0.1;
681
-
682
- const camX = playerPos.x - Math.sin(cameraRotation.y) * headForward;
683
- const camY = playerPos.y + neckHeight;
684
- const camZ = playerPos.z - Math.cos(cameraRotation.y) * headForward;
685
-
686
- camera.position.set(camX, camY, camZ);
687
-
688
- if (playerCharacter) {
689
- playerCharacter.visible = true;
690
- }
691
 
692
  camera.rotation.order = 'YXZ';
693
  camera.rotation.y = cameraRotation.y;
694
  camera.rotation.x = cameraRotation.x;
695
-
696
  updateCoordinates();
697
  renderer.render(scene, camera);
698
  }
699
-
700
  window.loadSpawn = function() {
701
  try {
702
  const input = document.getElementById('spawnInput').value;
@@ -709,20 +613,17 @@
709
  alert('❌ Invalid JSON format');
710
  }
711
  };
712
-
713
  window.copySpawn = function() {
714
  const spawnData = JSON.stringify(playerPos);
715
  navigator.clipboard.writeText(spawnData);
716
  alert('✅ Copied to clipboard: ' + spawnData);
717
  };
718
-
719
  const coordsDiv = document.getElementById('coordinates');
720
  const copyBtn = document.createElement('button');
721
  copyBtn.className = 'spawn-btn';
722
  copyBtn.textContent = 'Copy Spawn';
723
  copyBtn.onclick = window.copySpawn;
724
  coordsDiv.appendChild(copyBtn);
725
-
726
  init();
727
  </script>
728
  </body>
 
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
  <script type="module">
291
  import * as THREE from 'three';
292
  import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
293
+ let scene, camera, renderer, playerCube, garage;
 
 
294
  let playerPos = { x: 0, y: 1, z: 0 };
295
  let moveSideways = 0;
296
  let moveForwardBack = 0;
297
+ let moveSpeed = 0.06;
298
  let cameraRotation = { x: 0, y: 0 };
 
299
  let spawnPoint = { x: -3.5719999999999996, y: 1, z: 0.20199999999999968 };
300
  let joystickActive = false;
301
  let lookTouchId = null;
302
+ // Check orientation
 
 
 
 
 
303
  function checkOrientation() {
304
  const warning = document.getElementById('orientationWarning');
305
  if (window.innerHeight > window.innerWidth) {
 
312
  checkOrientation();
313
  window.addEventListener('resize', checkOrientation);
314
  window.addEventListener('orientationchange', checkOrientation);
 
315
  function init() {
316
  scene = new THREE.Scene();
317
  scene.background = new THREE.Color(0x1a1a2e);
318
  scene.fog = new THREE.Fog(0x1a1a2e, 5, 50);
 
319
  camera = new THREE.PerspectiveCamera(
320
  75,
321
  window.innerWidth / window.innerHeight,
322
  0.01,
323
  50
324
  );
 
325
  renderer = new THREE.WebGLRenderer({ antialias: true });
326
  renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
327
  renderer.setSize(window.innerWidth, window.innerHeight);
328
  renderer.shadowMap.enabled = true;
329
  document.body.appendChild(renderer.domElement);
330
+ // Lighting - MUCH MORE
331
  scene.add(new THREE.AmbientLight(0xffffff, 0.7));
332
 
333
  const dirLight1 = new THREE.DirectionalLight(0xffffff, 0.8);
 
343
  dirLight3.position.set(0, 20, -20);
344
  scene.add(dirLight3);
345
 
346
+ // Point lights for more fill
347
  const pointLight1 = new THREE.PointLight(0xffffff, 0.5, 50);
348
  pointLight1.position.set(10, 10, 10);
349
  scene.add(pointLight1);
 
355
  const pointLight3 = new THREE.PointLight(0xffffff, 0.4, 50);
356
  pointLight3.position.set(0, 5, 0);
357
  scene.add(pointLight3);
358
+ // Create player cube - SMALLER
359
+ const cubeGeometry = new THREE.BoxGeometry(0.5, 0.5, 0.5);
360
+ const cubeMaterial = new THREE.MeshPhongMaterial({ color: 0xff0000 });
361
+ playerCube = new THREE.Mesh(cubeGeometry, cubeMaterial);
362
+ playerCube.position.set(playerPos.x, playerPos.y, playerPos.z);
363
+ playerCube.castShadow = true;
364
+ scene.add(playerCube);
365
+ // Load garage
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
366
  const loader = new GLTFLoader();
367
  loader.load('./map.glb', (gltf) => {
368
  garage = gltf.scene;
 
384
  console.error('Error loading garage:', error);
385
  document.getElementById('loading').textContent = 'Error loading map.glb';
386
  });
 
387
  setupControls();
388
  animate();
 
389
  window.addEventListener('resize', () => {
390
  camera.aspect = window.innerWidth / window.innerHeight;
391
  camera.updateProjectionMatrix();
392
  renderer.setSize(window.innerWidth, window.innerHeight);
393
  });
394
  }
 
395
  function setupControls() {
396
  const joystick = document.getElementById('joystick');
397
  const joystickHandle = document.getElementById('joystickHandle');
398
  let joystickTouchId = null;
399
  let lastLookPos = { x: 0, y: 0 };
 
400
  joystick.addEventListener('touchstart', (e) => {
401
  joystickActive = true;
402
  joystickTouchId = e.touches[0].identifier;
403
  e.preventDefault();
404
  e.stopPropagation();
405
  });
 
406
  document.addEventListener('touchmove', (e) => {
407
  e.preventDefault();
408
 
409
+ // Handle all active touches
410
  for (let i = 0; i < e.touches.length; i++) {
411
  const touch = e.touches[i];
412
 
413
+ // Handle joystick touch
414
  if (joystickTouchId !== null && touch.identifier === joystickTouchId) {
415
  const rect = joystick.getBoundingClientRect();
416
  const centerX = rect.left + rect.width / 2;
 
419
  const dy = touch.clientY - centerY;
420
  const distance = Math.sqrt(dx * dx + dy * dy);
421
  const maxDistance = 60;
 
422
  if (distance > 5) {
423
  const limitedDistance = Math.min(distance, maxDistance);
424
  const normalizedDx = (dx / distance) * limitedDistance;
 
427
  joystickHandle.style.transform = `translate(calc(-50% + ${normalizedDx}px), calc(-50% + ${normalizedDy}px))`;
428
 
429
  moveForwardBack = -(dy / maxDistance);
430
+ // FIXED: Invert sideways movement
431
+ moveSideways = -(dx / maxDistance);
432
  } else {
433
  joystickHandle.style.transform = 'translate(-50%, -50%)';
434
  moveForwardBack = 0;
 
436
  }
437
  }
438
 
439
+ // Handle look touch (any touch that's not the joystick)
440
  if (touch.identifier !== joystickTouchId) {
441
  if (lookTouchId === null) {
442
+ // This is a new look touch
443
  const joystickRect = joystick.getBoundingClientRect();
444
  const coordsRect = document.getElementById('coordinates').getBoundingClientRect();
445
 
446
+ // Make sure not touching UI elements
447
  const notTouchingJoystick = !(touch.clientX >= joystickRect.left - 30 &&
448
  touch.clientX <= joystickRect.right + 30 &&
449
  touch.clientY >= joystickRect.top - 30 &&
 
457
  if (notTouchingJoystick && notTouchingCoords && touch.clientX < window.innerWidth * 0.85) {
458
  lookTouchId = touch.identifier;
459
  lastLookPos = { x: touch.clientX, y: touch.clientY };
 
 
460
  }
461
  } else if (touch.identifier === lookTouchId) {
462
+ // Update existing look touch
463
  const deltaX = touch.clientX - lastLookPos.x;
464
  const deltaY = touch.clientY - lastLookPos.y;
465
 
466
+ // MUCH higher sensitivity
467
+ cameraRotation.y -= deltaX * 0.012;
468
+ cameraRotation.x -= deltaY * 0.012;
469
+ cameraRotation.x = Math.max(-Math.PI / 2.5, Math.min(Math.PI / 2.5, cameraRotation.x));
470
 
471
  lastLookPos = { x: touch.clientX, y: touch.clientY };
472
  }
473
  }
474
  }
475
  }, { passive: false });
 
476
  document.addEventListener('touchend', (e) => {
477
+ // Check which touches ended
478
  const remainingTouchIds = Array.from(e.touches).map(t => t.identifier);
479
 
480
+ // Check if joystick touch ended
481
  if (joystickTouchId !== null && !remainingTouchIds.includes(joystickTouchId)) {
482
  joystickActive = false;
483
  joystickTouchId = null;
 
486
  moveSideways = 0;
487
  }
488
 
489
+ // Check if look touch ended
490
  if (lookTouchId !== null && !remainingTouchIds.includes(lookTouchId)) {
491
  lookTouchId = null;
492
  }
493
  });
 
494
  document.getElementById('upBtn').addEventListener('touchstart', (e) => {
495
  e.preventDefault();
496
  e.stopPropagation();
497
  playerPos.y += 0.5;
498
  });
 
499
  document.getElementById('downBtn').addEventListener('touchstart', (e) => {
500
  e.preventDefault();
501
  e.stopPropagation();
502
  playerPos.y = Math.max(0.5, playerPos.y - 0.5);
503
  });
504
+ document.addEventListener('touchstart', (e) => {
505
+ // The touchmove handler will pick up look touches automatically
506
+ });
507
  }
 
508
  function updateCoordinates() {
509
  document.getElementById('coordX').textContent = playerPos.x.toFixed(2);
510
  document.getElementById('coordY').textContent = playerPos.y.toFixed(2);
511
  document.getElementById('coordZ').textContent = playerPos.z.toFixed(2);
512
  }
 
513
  function checkCollisions(newPos) {
514
  if (!garage) return newPos;
515
+ const playerRadius = 0.15; // Much smaller radius
516
+
517
+ // Simple raycast collision
518
  const raycaster = new THREE.Raycaster();
519
  const directions = [
520
+ new THREE.Vector3(1, 0, 0), // Right
521
+ new THREE.Vector3(-1, 0, 0), // Left
522
+ new THREE.Vector3(0, 0, 1), // Forward
523
+ new THREE.Vector3(0, 0, -1), // Back
524
  ];
525
 
526
  const origin = new THREE.Vector3(newPos.x, newPos.y + 0.25, newPos.z);
 
540
  return newPos;
541
  }
542
 
543
+ // If blocked, try moving along individual axes with even smaller checks
544
  const tryX = { x: newPos.x, y: playerPos.y, z: playerPos.z };
545
  const tryZ = { x: playerPos.x, y: playerPos.y, z: newPos.z };
546
 
547
+ // Test X movement
548
  let xBlocked = false;
549
  const originX = new THREE.Vector3(tryX.x, tryX.y + 0.25, tryX.z);
550
  for (const dir of directions) {
 
556
  }
557
  }
558
 
559
+ // Test Z movement
560
  let zBlocked = false;
561
  const originZ = new THREE.Vector3(tryZ.x, tryZ.y + 0.25, tryZ.z);
562
  for (const dir of directions) {
 
568
  }
569
  }
570
 
571
+ // Allow movement on any unblocked axis
572
  if (!xBlocked) return tryX;
573
  if (!zBlocked) return tryZ;
574
 
575
  return playerPos;
576
  }
 
577
  function animate() {
578
  requestAnimationFrame(animate);
579
+ // Calculate movement based on camera direction (always, not just when joystick active)
580
+ // Forward/backward relative to camera
 
 
 
 
 
 
 
 
 
 
 
 
581
  const forwardX = -Math.sin(cameraRotation.y) * moveForwardBack * moveSpeed;
582
  const forwardZ = -Math.cos(cameraRotation.y) * moveForwardBack * moveSpeed;
583
 
584
+ // Left/right strafe relative to camera (perpendicular to forward)
585
+ const strafeX = -Math.sin(cameraRotation.y + Math.PI / 2) * moveSideways * moveSpeed;
586
+ const strafeZ = -Math.cos(cameraRotation.y + Math.PI / 2) * moveSideways * moveSpeed;
587
  const newPos = {
588
  x: playerPos.x + forwardX + strafeX,
589
  y: playerPos.y,
 
592
 
593
  playerPos = checkCollisions(newPos);
594
 
595
+ playerCube.position.set(playerPos.x, playerPos.y, playerPos.z);
596
+ camera.position.set(playerPos.x, playerPos.y + 1.6, playerPos.z);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
597
 
598
  camera.rotation.order = 'YXZ';
599
  camera.rotation.y = cameraRotation.y;
600
  camera.rotation.x = cameraRotation.x;
 
601
  updateCoordinates();
602
  renderer.render(scene, camera);
603
  }
 
604
  window.loadSpawn = function() {
605
  try {
606
  const input = document.getElementById('spawnInput').value;
 
613
  alert('❌ Invalid JSON format');
614
  }
615
  };
 
616
  window.copySpawn = function() {
617
  const spawnData = JSON.stringify(playerPos);
618
  navigator.clipboard.writeText(spawnData);
619
  alert('✅ Copied to clipboard: ' + spawnData);
620
  };
 
621
  const coordsDiv = document.getElementById('coordinates');
622
  const copyBtn = document.createElement('button');
623
  copyBtn.className = 'spawn-btn';
624
  copyBtn.textContent = 'Copy Spawn';
625
  copyBtn.onclick = window.copySpawn;
626
  coordsDiv.appendChild(copyBtn);
 
627
  init();
628
  </script>
629
  </body>