I have a question that maybe it is an easy calculation but I am a motion graphic designer not a Math guy so... here it goes. I have a 3D scene with a perspective camera in it. I want to make a 2D object in the scene to rotate on Y axis to always look in the direction of the camera so from the Camera point of view it won't be visible as a 2D object.
So I can get the values of camera X and Z position and use them to calculate the Y rotation but I am not sure what is the math I should do.
currently I want to leave camera Y position (height) out of it.
I am attaching some photos to maybe make it clearer: Pos1 Pos2 Pos3
Thanks in advance.
As David K already suggested you can use
atan2funtion.It's a special version of
arcus tangensthat takes into account all possible ranges and signs of input values and returns an angle.Just compute a vector from your rotating object to target (Camera) and put its X and Y into an
atan2function. The result will be a rotation angle, in Radians.