Answer the question
In order to leave comments, you need to log in
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);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question