title: Detect Collision Is not 100% accurate
body: <p>Im creating simple endless runner game in Three.js. Idea is simple. 3 lines and object spawning.
  Here is my code for object spawning and collision detection is in it.
  Problem is it sometimes work and sometimes not.
  It always detect first spawned object. Next are totally random.</p>
  <pre><code>function spawnObjects(scene, car) {
    var objectsArray = [];
  
    var xPositions = [-70, 0, 70];
    var zOffset = [-500, -100, 0, 100, 200, 300, 400, 500, 600, 1000];
  
    for (let i = 0; i &lt; 15; i++) {
      const geometry = new THREE.BoxGeometry(50, 70, 10);
      const material = new THREE.MeshPhongMaterial({
        color: 0x123456,
        emissive: 0x654321,
      });
      const mesh = new THREE.Mesh(geometry, material);
  
      var randomX = xPositions[Math.floor(Math.random() * xPositions.length)];
      mesh.position.set(randomX, 0, -1000 - i * 1000);
      objectsArray.push(mesh);
      scene.add(mesh);
    }
  
    function animate() {
      requestAnimationFrame(animate);
  
      renderer.render(scene, camera);
  
      objectsArray.forEach(function (obj) {
        obj.position.z += 7;
  
        if (obj.position.z &gt;= 50) {
          var randomX = xPositions[Math.floor(Math.random() * xPositions.length)];
          var randomZ = zOffset[Math.floor(Math.random() * zOffset.length)];
          obj.position.z = -7000 - randomZ;
          obj.position.x = randomX;
        } else if (
          car.position.z == obj.position.z &amp;&amp;
          car.position.x == obj.position.x
        ) {
          alert(&quot;Collision Detected&quot;);
        }
      });
    }
  
    animate();
  }
  </code></pre>