I am currently working on a project where I need a 3D object to follow a specified path while always facing the direction in which it is moving. To achieve this, I have been using the following code snippet:
fishObject.quaternion.setFromAxisAngle(axis, radians)
In this context, radians
represents the angle between an up
vector and the direction of travel.
Within the provided pen, you can visualize the axes for better understanding. The blue line represents the axis
, the purple one symbolizes up
, and the red line illustrates the intended direction for the fish (tangent
). Even though these components move correctly, the object's rotation does not align with its axis when setting the quaternion.
The pen may seem cluttered due to the fish construction details, but my main focus is line 281 and its parameters:
fishObject.quaternion.setFromAxisAngle(axis, radians)
Being new to this concept, I believe resolving this issue should be straightforward for someone experienced in 3D rotations.
Your guidance and clarity on this matter would be greatly appreciated. Thank you.