i used the example code you gave in the previous discussion which should theoretically console.log the objects being collided with a BufferGeometry fixed to the cameras position but this does not detect colisions…
i’m uncertain what i’m doing wrong for the collisions to not be detected and wondering if you could help me debug the issue, what i might be missing, what i’m doing wrong and if there might be a simpler way of doing this?
Assuming MovingCube is not the child of another 3D object it’s fine. However, you should normalize the direction vector since they always have unit length. Meaning directionVector.normalize().
hey man, thanks for the help! i’m not sure if what i’ve done is exactly what you meant but i’ve managed to get it to work, it doesn’t feel like the right solution as i feel like there are now things that i don’t necissarily need in there… here’s what i have, which is detecting collisions…
const originPoint = MovingCube.geometry.getAttribute( 'position' );
const localVertex = new THREE.Vector3();
const globalVertex = new THREE.Vector3();
for (let vertexIndex = 0; vertexIndex < originPoint.count; vertexIndex++)
{
localVertex.fromBufferAttribute( originPoint, vertexIndex );
globalVertex.copy( localVertex ).applyMatrix4( MovingCube.matrixWorld );
}
const directionVector = globalVertex.sub( MovingCube.position );
var ray = new THREE.Raycaster( MovingCube.position, directionVector.normalize() );
var collisionResults = ray.intersectObjects( collidableMeshList );
if ( collisionResults.length > 0 && collisionResults[0].distance < directionVector.length() && collisionResults[0].object.name == 'wally'){
console.log("collision obect 1");
}
would you say this is right or would you say there’s a proper way?