防止一个形状被鼠标拖过另一个THREE.js

时间:2018-06-13 02:22:43

标签: three.js collision-detection

当我用鼠标拖动它时,我正试图阻止一个物体穿过另一个物体。碰撞检测工作正常,我只需要防止形状被拖过其他形状。

setForCollision: function(symbol){

let cube = new THREE.Box3().setFromObject(this.centerCube[1]);//shape is fixed in place
let cube1      = new THREE.Box3().setFromObject(symbol);//dragging with mouse

if(cube1.isIntersectionBox(cube)){
    console.log(shapes touched);
    //I tried repositioning. It repositions it but doesn't really stop me from dragging it. Any suggestions?
    symbol.position.set(0,0,0);


}

let cube = new THREE.Box3().setFromObject(this.centerCube[1]);//shape is fixed in place let cube1 = new THREE.Box3().setFromObject(symbol);//dragging with mouse if(cube1.isIntersectionBox(cube)){ console.log(shapes touched); //I tried repositioning. It repositions it but doesn't really stop me from dragging it. Any suggestions? symbol.position.set(0,0,0); }

1 个答案:

答案 0 :(得分:0)

显然以下是有效的。我只需稍微调整一下坐标就可以正常工作了。

object.position.set(-7,-10,1);