I'm struggling to understand how to utilize the three.js camera effectively.
https://i.sstatic.net/7sYb8.png
My goal is to have a small map where players can spawn at the corners, depicted as cubes labeled 1, 2, 3, and 4 on the sketch provided.
My aim is for the camera to initially be positioned behind the players, represented by the "eye" icon in my sketch, pointing towards cube 1 with an orange line indicating the line of sight. I've also illustrated where I want the camera to be if I were the fourth player.
However, during testing, I encountered unexpected behavior. Currently, this is what I am attempting:
camera.position.set(player.position.x, player.position.y + 2, player.position.z + 3);
camera.lookAt(player.position);
The player
variable refers to a THREE.Mesh object. While the camera positioning works correctly when the player spawns in positions 1 or 3, it behaves incorrectly in position 2. When I try to rotate around the player using the mouse, the camera rotates as if it's spinning on the Y-axis and obscures my view of the cube. Initially, I believed that utilizing the lookAt()
method on the player would align the camera properly, but evidently, I was mistaken.
Could someone clarify why this isn't functioning as expected?