Reaperxxxx commited on
Commit
9d90a40
·
verified ·
1 Parent(s): 5dad437

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +40 -5
index.html CHANGED
@@ -155,7 +155,8 @@
155
  let cameraDistance = 8;
156
  let cameraHeight = 3;
157
  let moveDirection = { x: 0, z: 0 };
158
- let moveSpeed = 0.3;
 
159
 
160
  function init() {
161
  scene = new THREE.Scene();
@@ -224,10 +225,12 @@
224
 
225
  joystick.addEventListener('touchstart', (e) => {
226
  isJoystickActive = true;
 
227
  });
228
 
229
  joystick.addEventListener('touchmove', (e) => {
230
  if (!isJoystickActive) return;
 
231
  const touch = e.touches[0];
232
  const rect = joystick.getBoundingClientRect();
233
  const centerX = rect.left + rect.width / 2;
@@ -240,16 +243,18 @@
240
  if (distance > 0) {
241
  const angle = Math.atan2(dy, dx);
242
  const limitedDistance = Math.min(distance, maxDistance);
243
- joystickHandle.style.transform = `translate(calc(-50% + ${Math.cos(angle) * limitedDistance}px), calc(-50% + ${Math.sin(angle) * limitedDistance}px))`;
 
244
 
245
- moveDirection.x = Math.cos(angle);
246
- moveDirection.z = Math.sin(angle);
247
  }
248
  });
249
 
250
  joystick.addEventListener('touchend', () => {
251
  isJoystickActive = false;
252
- joystickHandle.style.transform = 'translate(-50%, -50%)';
 
253
  moveDirection.x = 0;
254
  moveDirection.z = 0;
255
  });
@@ -262,6 +267,36 @@
262
  document.getElementById('downBtn').addEventListener('touchstart', () => {
263
  playerPos.y = Math.max(0.5, playerPos.y - 0.5);
264
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265
  }
266
 
267
  function updateCoordinates() {
 
155
  let cameraDistance = 8;
156
  let cameraHeight = 3;
157
  let moveDirection = { x: 0, z: 0 };
158
+ let moveSpeed = 0.1;
159
+ let cameraRotation = { x: 0, y: 0 };
160
 
161
  function init() {
162
  scene = new THREE.Scene();
 
225
 
226
  joystick.addEventListener('touchstart', (e) => {
227
  isJoystickActive = true;
228
+ e.preventDefault();
229
  });
230
 
231
  joystick.addEventListener('touchmove', (e) => {
232
  if (!isJoystickActive) return;
233
+ e.preventDefault();
234
  const touch = e.touches[0];
235
  const rect = joystick.getBoundingClientRect();
236
  const centerX = rect.left + rect.width / 2;
 
243
  if (distance > 0) {
244
  const angle = Math.atan2(dy, dx);
245
  const limitedDistance = Math.min(distance, maxDistance);
246
+ joystickHandle.style.left = `calc(50% + ${Math.cos(angle) * limitedDistance}px)`;
247
+ joystickHandle.style.top = `calc(50% + ${Math.sin(angle) * limitedDistance}px)`;
248
 
249
+ moveDirection.x = Math.cos(angle) * (distance / maxDistance);
250
+ moveDirection.z = Math.sin(angle) * (distance / maxDistance);
251
  }
252
  });
253
 
254
  joystick.addEventListener('touchend', () => {
255
  isJoystickActive = false;
256
+ joystickHandle.style.left = '50%';
257
+ joystickHandle.style.top = '50%';
258
  moveDirection.x = 0;
259
  moveDirection.z = 0;
260
  });
 
267
  document.getElementById('downBtn').addEventListener('touchstart', () => {
268
  playerPos.y = Math.max(0.5, playerPos.y - 0.5);
269
  });
270
+
271
+ // Look around with finger on middle of screen
272
+ let isLooking = false;
273
+ let lastLookPos = { x: 0, y: 0 };
274
+
275
+ document.addEventListener('touchstart', (e) => {
276
+ const touch = e.touches[0];
277
+ if (touch.clientX > window.innerWidth * 0.4 && touch.clientX < window.innerWidth * 0.6 &&
278
+ touch.clientY > window.innerHeight * 0.3 && touch.clientY < window.innerHeight * 0.7) {
279
+ isLooking = true;
280
+ lastLookPos = { x: touch.clientX, y: touch.clientY };
281
+ }
282
+ });
283
+
284
+ document.addEventListener('touchmove', (e) => {
285
+ if (!isLooking || e.touches.length > 1) return;
286
+ const touch = e.touches[0];
287
+ const deltaX = touch.clientX - lastLookPos.x;
288
+ const deltaY = touch.clientY - lastLookPos.y;
289
+
290
+ cameraRotation.y += deltaX * 0.01;
291
+ cameraRotation.x += deltaY * 0.01;
292
+ cameraRotation.x = Math.max(-Math.PI / 2, Math.min(Math.PI / 2, cameraRotation.x));
293
+
294
+ lastLookPos = { x: touch.clientX, y: touch.clientY };
295
+ });
296
+
297
+ document.addEventListener('touchend', () => {
298
+ isLooking = false;
299
+ });
300
  }
301
 
302
  function updateCoordinates() {