好,所以我试图在 Three.js javascript中测试两个立方体是否碰撞。它不起作用...可悲的是。 我看到了另一个这样的问题,但答案对我没有用。这是我的代码(不是我的所有代码)以及失败的冲突检测。 -
var plrHead = new THREE.Mesh(geometry, skin)//this is the players head(the one to detect the collision)
var blocks = [//all the other meshes]
// there is a lot of code that i don't want to show
// basically using - if (oncollide()){}
冲突检测失败
function onCollide() {
for (var vertexIndex = 0; vertexIndex < plrHead.geometry.vertices.length; vertexIndex++)
{
var localVertex = plrHead.geometry.vertices[vertexIndex].clone();
var globalVertex = localVertex.applyMatrix4( plrHead.matrix );
var directionVector = globalVertex.sub( plrHead.position );
var ray = new THREE.Raycaster( originPoint, directionVector.clone().normalize() );
var collisionResults = ray.intersectObjects( blocks );
if (collisionResults.length > 0 && collisionResults[0].distance < directionVector.length() ) {
return true
}
}
}
是的,如果有人知道如何检测网格之间的碰撞,那就谢谢!