I currently attempt to rotate a object in the game to face toward another object, but stuck on
how to find angle on x axis between two vectors(if that makes sense).
The final transform for the object to be rotated( and moved) is
translatation matrix * rotation matrix on y axis(0,1,0) * rotation matrix on x axis(1,0,0)
So it can be rotated left and right, and up and down to face its target when moving to it. I figured out in order to rotate on y axis, I need to make the y component of the object's target direction vector ( target position - object position ) zero, like vec3(targetDirection.x, 0, targetDirection.z), and find the angle between target direction vector and the object's default direction vector, which is always (0,0,-1). It works fine but I can't figure out how to find the angle on the x axis. Using the same trick, making the x component zero instead of y component, it doesn't work.
The two vectors are target direction vector ( target position - object position) and object's default
direction vector which I always set to vec3(0,0,-1). Thanks.