I have a scenario where an Entity is traversing a CatmullRomCurve3
path, moving left with the left
or down
arrow keys and right with the right
or up
arrow keys.
Initially, I encountered an issue where I wanted the Entity to face perpendicular to the path at 90 degrees instead of in the same direction as the path. You can refer to my code for this scenario here. The problem was resolved with this solution.
In essence, I had to incorporate the following code to rotate the entity:
entity.lookAt((point2).sub(point1).applyAxisAngle(axis, -Math.PI * 0.5).add(point1));
Although the entity now rotates correctly, a new issue arose where the camera
was not aligning with the entity or moving along with it (I desired a third-person perspective of the entity); however, attaching the camera as a child of the entity solved the problem!
The Current Issue
Now, my objective is to have the entity initially face 90 degrees away from the path, but upon pressing the left
or down
arrows, I want the entity to face left (along the path as originally intended), and face the opposite direction when the right
or up
arrows are pressed.
I achieved this by utilizing some conditional statements in the render
loop to adjust the value of -Math.PI * 0.5
to either -Math.PI * 2
or -Math.PI * 0.5
for the left and right directions based on the key pressed.
However, this adjustment also influences the camera, which shares the updated lookAt
value since it is linked to the entity. I want the camera to maintain its position consistently (facing 90 degrees from the path, just like the entity when stationary).
How can I prevent the camera from rotating/moving/changing its lookAt
orientation when the entity rotates?
It seems that any modifications I make to the camera have no effect, as it remains fixed to the entity's orientation.
Appreciate your assistance.