N
N
Nicholas2015-10-20 19:08:05
JavaScript
Nicholas, 2015-10-20 19:08:05

How to make a normal hittest in Three.js?

I did a hittest but it works every other time! I can not understand why ..
Code:

var shipSphere=DEMO.Hero_Array[2].object;
          var collidableMeshList=DEMO.attack_ball;
          
          var originPoint = shipSphere.position.clone();
          
          for (var vertexIndex = 0; vertexIndex < shipSphere.geometry.vertices.length; vertexIndex++)
          {
            var localVertex = shipSphere.geometry.vertices[vertexIndex].clone();
            var globalVertex = localVertex.applyMatrix4(shipSphere.matrix);
            var directionVector = globalVertex.sub(shipSphere.position);

            var ray = new THREE.Raycaster(originPoint, directionVector.clone().normalize());
            
            var collisionResults = ray.intersectObjects(collidableMeshList);
            
            if (collisionResults.length > 0 && collisionResults[0].distance < directionVector.length() + 20)
            {
              //console.log('attack_ball');
              
              DEMO.ms_Scene.remove( DEMO.attack_ball[key] ); // Удалим объект со сцены
              
              if (DEMO.attack_ball[key] != undefined){

                
                UBUTUBU.ThreeJS.Explosion.Add(DEMO.attack_ball[key].position.x + 10 , DEMO.attack_ball[key].position.z , DEMO.attack_ball[key].position.y);
                
                
                DEMO.attack_ball[key].delete; 
                DEMO.attack_ball.splice(key,1);
              }
            }
          }

Maybe there are other options?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GreatRash, 2015-10-20
@GreatRash

mrdoob.github.io/three.js/examples/canvas_interact... (CTRL+U)
also

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question