Collision detection not working anymore

This code once worked according to threejs-cookbook/07.06-add-simple-detection-collision.html at b954c5af0eae8a9710afa6afb810bd13b6c32817 · josdirksen/threejs-cookbook · GitHub

Unfortunately this code is outdated. Does someone know how to make the following code work for the “new” bufferGeometry

function checkCollision() {

        cubes.forEach(function (cube) {
            cube.material.transparent = false;
            cube.material.opacity = 1.0;


        var cube = scene.getObjectByName('cube');
        var originPoint = cube.position.clone();

        for (var vertexIndex = 0; vertexIndex < cube.geometry.vertices.length; vertexIndex++) {
            var localVertex = cube.geometry.vertices[vertexIndex].clone();
            var globalVertex = localVertex.applyMatrix4(cube.matrix);
            var directionVector = globalVertex.sub(cube.position);

            var ray = new THREE.Raycaster(originPoint, directionVector.clone().normalize());
            var collisionResults = ray.intersectObjects(cubes);
            if (collisionResults.length > 0 && collisionResults[0].distance < directionVector.length()) {
                collisionResults[0].object.material.transparent = true;
                collisionResults[0].object.material.opacity = 0.4;

You have to use …geometry.attributes.position and geometry.attributes.normal to calculate ray position and direction on buffergeometry, you can utilise arrowHelper to visualize where rays are going from / to.

Thanks for your answer @forerunrun. I still have one problem remaining when applying this code. The code is only working for one side, you know what I mean if I show you my demo: Collision detection at its finest (demo) - YouTube. Do you know the solution to this problem?