I've looked around at loads of solutions that others have suggested around this, and I have a certain amount of collision detection already that works fine. But this is centred around one object colliding with many... however I now have to counter for bullets. So I have many objects that could collide with many.
Here's my basic collision detection for my Hero smashing into walls.
for (var vertexIndex = 0; vertexIndex < hero.geometry.vertices.length; vertexIndex++){
var localVertex = hero.geometry.vertices[vertexIndex].clone();
var globalVertex = hero.matrix.multiplyVector3(localVertex);
var directionVector = globalVertex.sub( hero.position );
var ray = new THREE.Raycaster( hero.position, directionVector.clone().normalize() );
var collisionResults = ray.intersectObjects( collidableMeshList );
if ( collisionResults.length > 0 && collisionResults[0].distance < directionVector.length() )
{
console.log('BANG!')
}
}
The trouble is if I put this same detection code in a loop for each of the bullets it naturally slows down to an unusable speed.
Is there a more basic detection that I can implement that will tackle this?
I'm slowly getting my heads around three.js and am sure I'm missing something simple but just couldn't understand other examples. Any help or a good point in the right direction would be greatly appreciated.
Edit
I've been playing around, obviously my first attempts have failed and I'm not much closer but wondering if I would be closer on the lines if I was to try getting the bullets position and see if its position is within the my an object inside my collisions array.
Not sure, I've seen that plenty of people have come across this before but struggling to find a solution that is defined enough for me to understand.