Update index.html
Browse files- index.html +19 -10
index.html
CHANGED
@@ -228,15 +228,24 @@
|
|
228 |
}
|
229 |
|
230 |
const camera = document.querySelector('[camera]');
|
231 |
-
const cameraPosition = camera.
|
232 |
-
const cameraRotation = camera.
|
233 |
-
|
234 |
-
// Calculate
|
235 |
-
const
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|