awacke1 commited on
Commit
8cb8d52
·
verified ·
1 Parent(s): cf85c1d

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +19 -10
index.html CHANGED
@@ -228,15 +228,24 @@
228
  }
229
 
230
  const camera = document.querySelector('[camera]');
231
- const cameraPosition = camera.getAttribute('position');
232
- const cameraRotation = camera.getAttribute('rotation');
233
-
234
- // Calculate position 3 units in front of the camera
235
- const radians = THREE.MathUtils.degToRad(cameraRotation.y);
236
- const x = cameraPosition.x - Math.sin(radians) * 3;
237
- const z = cameraPosition.z - Math.cos(radians) * 3;
238
-
239
- targetObject.setAttribute('position', `${x} ${cameraPosition.y} ${z}`);
 
 
 
 
 
 
 
 
 
240
 
241
  // Update position inputs if the object is selected
242
  if (targetObject === selectedObject) {
@@ -337,11 +346,11 @@
337
  }
338
 
339
  function spawnSpawner() {
 
340
  const spawner = document.createElement('a-entity');
341
  spawner.setAttribute('geometry', 'primitive: box; width: 2; height: 2; depth: 2');
342
  spawner.setAttribute('material', 'color: purple');
343
  spawner.setAttribute('class', 'spawner');
344
- const angle = Math.random() * Math.spawner.setAttribute('class', 'spawner');
345
  const angle = Math.random() * Math.PI * 2;
346
  const radius = 15 + Math.random() * 10;
347
  const x = Math.cos(angle) * radius;
 
228
  }
229
 
230
  const camera = document.querySelector('[camera]');
231
+ const cameraPosition = camera.object3D.position;
232
+ const cameraRotation = camera.object3D.rotation;
233
+
234
+ // Calculate the direction the camera is looking
235
+ const direction = new THREE.Vector3(0, 0, -1);
236
+ direction.applyQuaternion(camera.object3D.quaternion);
237
+
238
+ // Set the distance to be similar to where the Score is (5 units away)
239
+ const distance = 5;
240
+
241
+ // Calculate the new position
242
+ const newPosition = new THREE.Vector3(
243
+ cameraPosition.x + direction.x * distance,
244
+ cameraPosition.y + direction.y * distance,
245
+ cameraPosition.z + direction.z * distance
246
+ );
247
+
248
+ targetObject.setAttribute('position', newPosition);
249
 
250
  // Update position inputs if the object is selected
251
  if (targetObject === selectedObject) {
 
346
  }
347
 
348
  function spawnSpawner() {
349
+ const spawner = document.createElement('a-entityfunction spawnSpawner() {
350
  const spawner = document.createElement('a-entity');
351
  spawner.setAttribute('geometry', 'primitive: box; width: 2; height: 2; depth: 2');
352
  spawner.setAttribute('material', 'color: purple');
353
  spawner.setAttribute('class', 'spawner');
 
354
  const angle = Math.random() * Math.PI * 2;
355
  const radius = 15 + Math.random() * 10;
356
  const x = Math.cos(angle) * radius;