If I have a three.js mesh along with a velocity vector3.
Elsewhere, the velocity is modified and then added to the mesh.position every frame.
My goal is to have the mesh.rotation aligned with the velocity, making the mesh act like an arrow always pointing in the direction it's moving.
I've attempted two methods, both causing the mesh to rotate inaccurately and in reverse.
//attempt 1
mesh.rot.x = Math.atan2( vel.y, vel.z );
mesh.rot.y = -Math.atan2( vel.x, vel.z );
mesh.rot.z = Math.atan2( vel.x, vel.y );
//attempt 2 inspired from a related stackoverflow post; also unsuccessful
mesh.rot.y = Math.asin( vel.z );
mesh.rot.z = Math.atan2( vel.y, vel.x );
var bankVec = new Vector3( -vel.y, vel.x, 0 );
var upVec = new Vector3( dot( bankVec, vel ) );
mesh.rot.x = Math.atan2(dot(bankVec, vel) / dot(upVec, vel),abs(bankVec)*abs(upVec));
Vector math is quite confusing to me.
Currently, I am randomly changing signs and parameters, hoping for a solution. Any guidance on the appropriate use of dot products, cross products, atan2's would be greatly welcomed.
Not seeking code, just understanding the relevant equations involving dot products, cross products, atan2's, etc.