立方体应该保持平坦,但朝向光标旋转,只有一种类型的旋转(2d -自上而下)。我现在担心的是,这可能是由于网格对自身的中心?请帮帮我!
点击此处查看:https://thecoop.group/conquest/ground
以下是摘录,我尝试了许多不同的方法,一些实验代码可能会保留下来:
const plane = new Plane(new Vector3(0, 1, 0), 1);
const raycaster = new Raycaster();
const mouse = new Vector2();
const pointOfIntersection = new Vector3();
document.addEventListener('mousemove', ev => {
const { camera, me } = window.GROUND_LEVEL;
mouse.x = ( ev.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( ev.clientY / window.innerHeight ) * 2 + 1;
raycaster.setFromCamera(mouse, camera);
raycaster.ray.intersectPlane(plane, pointOfIntersection);
if (me.mesh) {
// Attempt to make mesh "look at" (rotate) to target position.
me.mesh.geometry.lookAt(pointOfIntersection);
}
});发布于 2021-07-08 22:05:09
pointOfIntersection有3个维度,对应于立方体的三个轴。
如果只希望立方体在一个轴上旋转,请尝试在Object3D#lookAt中为其他轴指定0。
// The cube will rotate on its Y axis when following a point on the X axis
me.mesh.geometry.lookAt(pointOfIntersection.x, 0, 0);https://stackoverflow.com/questions/68271790
复制相似问题