# Finding the relative angle between two gameObjects (+ve and -ve)

Hi, sorry if this is answered elsewhere, I’ve looked, but can’t find what I’m looking for.
Basically, I have a 3rd person game, and when the mouse is clicked, a projectile is instantiated at a gameEmpty near the player’s hand. So far, so good, but as the projectile spawns as (transform.rotation), it will only be thrown in the direction the player is pointing, making aiming difficult.
What I want to happen is to determine the angle in the Y axis difference between the player and camera, and use this angle to alter the rotation of the spawned object, so it’s thrown in the direction the camer is looking.
I could use the camera.rotation in the instantiate code, but I want to impose limits on the angle (say +/- 20 degrees of forwards, which would need the angle difference.
From what I’ve gleaned from other threads, you can find the angle between two vectors, but I need the relative angle.
I don’t expect anyone to write the code for me, but any help pushing me in the right direction would be appreciated greatly, thanks

You could use this:

``````var cam = Camera.main.transform;
var angleY = Mathf.Asin(Vector3.Cross(cam.forward, weapon.forward).y) * Mathf.Rad2Deg;
``````

The cross product of two vectors returns a vector perpendicular to the plane formed by them, and its length is proportional to the sine of the angle between the two vectors. Since you want the horizontal angle, you can get the arc-sine of cross.y - better than the length, cross.y conserves the signal, thus you will get positive angles to one side and negative to the other.