intersectsMesh Babylon.js

60 Views Asked by At

I am creating a project in which it is necessary to return an object to certain coordinates when it intersects with another object

Here's the source code, what's wrong?

Thanks!

const createScene =  () => {
    const scene = new BABYLON.Scene(engine);

    const camera = new BABYLON.ArcRotateCamera("camera", -Math.PI / 2, Math.PI / 2.5, 3, new BABYLON.Vector3(0, 0, 0));
    camera.attachControl(canvas, true);

    const light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(0, 1, 0));
    const box = BABYLON.MeshBuilder.CreateBox("box", {});

    pointerDragBehavior2 = new BABYLON.PointerDragBehavior({ dragPlaneNormal: new BABYLON.Vector3(0, 1, 0) });
    pointerDragBehavior2.useObjectOrientationForDragging = false;
    
    box.addBehavior(pointerDragBehavior2);


    const sphere = BABYLON.MeshBuilder.CreateSphere("sphere", {});
    sphere.position.x = 5;
    
    if (box.intersectsMesh(sphere, false)) {
        box.position.x = 0;
        box.position.y = 0;
        box.position.z = 0;
    }

    return scene;
}

I tried to do it with this code, but it didn't work out, what am I doing wrong?

0

There are 0 best solutions below