1
我在Three.js中創建了一個可玩的迷宮。所有的物體 - 地板,天花板和牆壁 - 都放置在正X軸和Z軸內。相機被放置這樣的:攝像頭控件與他們應該是相反的。爲什麼?
camera = new THREE.PerspectiveCamera(45,
window.innerWidth/window.innerHeight,
0.1,
1000
);
camera.position.set(0, 0.25, 0);
// The camera is placed pointing to the nearest open path from the
// initial position. Check mazeGenerator.js for the reference of
// "coordinates".
if(grid[1][0] == coordinates.W)
{
camera.lookAt(new THREE.Vector3(1, 0.25, 0));
}
else
{
camera.lookAt(new THREE.Vector3(0, 0.25, 1));
}
,並將其移動這樣的:
function keyboardCheck()
{
var movementSpeed = 0.02;
var rotationSpeed = 0.03;
if(keyboard.pressed('w') || keyboard.pressed('up'))
{
camera.translateZ(-movementSpeed);
}
if(keyboard.pressed('a') || keyboard.pressed('left'))
{
camera.rotateY(rotationSpeed);
}
if(keyboard.pressed('d') || keyboard.pressed('right'))
{
camera.rotateY(-rotationSpeed);
}
}
如果我把相機沒有lookAt
功能,它似乎面臨[0, 0, 0]
,但當然是我想要的要做的是通過使相機面對最近的開放路徑來幫助玩家一點點。
爲了使它前進,我必須減少Z,因爲否則當你點擊「向前移動」鍵時,它會倒退。這讓我認爲,即使我告訴相機看一個方向,對象的Z軸與世界的Z軸相反。
問題本身就是:爲什麼會發生這種情況?
非常感謝您提前。
- https://github.com/MikelAlejoBR/3D-Maze-95/tree/0.4
- https://github.com/MikelAlejoBR/3D-Maze-95/issues/8
克里斯塔爾清楚。謝謝 :) – MikelAlejoBR