我想將一個子對象(圓柱體)與另一個對象(cube2)對齊。我使用了lookAt函數,但對齊方式不正確。我的錯誤在哪裏?three.js lookAt函數無法正常工作
我有以下代碼:
//cube 1
var cube=new THREE.BoxGeometry(2,2,2);
var material=new THREE.MeshBasicMaterial ({ color: 0xffffff });
mesh1=new THREE.Mesh(cube,material);
mesh1.position.set(-2,2,0);
scene.add(mesh1);
//cube 2
var cube2=new THREE.BoxGeometry(2,2,2);
var material=new THREE.MeshBasicMaterial ({ color:0x000000 });
mesh2=new THREE.Mesh(cube2,material);
mesh2.position.x=6;
mesh2.position.y=2;
scene.add(mesh2);
//cylinder
var cylinder=new THREE.CylinderGeometry(1,1,5,30);
var material=new THREE.MeshBasicMaterial({ color:0xff3399 });
mesh3=new THREE.Mesh(cylinder,material);
mesh3.position.x=4.5;
mesh3.lookAt(mesh2.position);
mesh1.add(mesh3);
左邊的立方體是cube1和正確的立方體是CUBE2。圓柱體是cube1的子元素,應該看起來像cube2。所以如果我移動立方體1(在y位置),圓柱體應該旋轉並且始終看着立方體2。
注視totate對網在空間中的矢量,在哪裏添加。 – Martin
你有解決我的問題的方法嗎? – webgl
mesh3.lookAt(mesh2.position.subVectors(mesh2.position,mesh1.position))?? – Martin