I have two 3d vectors containing position data for two objects within my game. One of the objects needs to turn its camera directly to the other based on the current positions (the setting of the pitch/yaw are absolute so realistically I can ignore those two variables). What I need help with is the math, honestly I just can't find anything about doing this properly.
//An example in pseudocode
//(x, y, z)
Vector3 mychar = new Vector3(100, 100, 100);
Vector3 explosion = new Vector3(555, 1000, 300);
//(pitch, yaw)
Vector2 myRotation = new Vector2(0, 0); //Can assume this is always the case because the setting of rotation is absolute rather than relative
Vector2 expRotation = new Vector2(35, 14);
//The math I cant seem to figure out would be in this function
Vector2 newRotationj = GetRotationBetween(myRotation, mychar, explosion);
Here's what I have so far but I'm getting problems with the Y rotations (its the "up" direction and the horizon is at 0 degrees) Randomly my character will look in the mirrored direction in y (IE if the object is -20 below horizon it does +20) however it's only sometimes and I dont see where my math is wrong.
float dx = posIt.x - posMe.x;
float dy = posIt.y - posMe.y;
float dz = posIt.z - posMe.z;
yaw = Convert.ToSingle(Math.Atan(dx / dz) * 180 / Math.PI);
pitch = Convert.ToSingle(Math.Atan(dy / dz) * 180 / Math.PI);