So I have two sprites and I want one to face the other in a creepy Mona-Lisa-eyes-following kinda way.
Just in case I fail to edit this correctly at a later stage, I should mention that I'm m aking a 2D game, and so I'm actually only interested in rotation around a single axis.
To do this I...
As input we have the position of two sprites in 3D space, AnnoyingSpriteFacingMe and Player.
The
Quaternions is how Unity stores rotations, and so it is with these that we play.
Some code. In this example I am calculating the angle which the attacking boat should be on in 2D space in order to fire its cannons at the other boat.
public Quaternion desirableAngleForFiring(Vector3 attackingBoat, Vector3 defendingBoat){
// from a from and a to calculate the angle, then add 90
Vector3 targetDir = defendingBoat - attackingBoat;
float angle = (float) Mathf.Atan2(targetDir.x, targetDir.z) * Mathf.Rad2Deg;;
return Quaternion.Euler(0, angle+90, 0);
}