I don’t even know how to Google my question to find an answer so I drew a picture, below. I have a weapon who’s Field of Fire I’m trying to rotate so a target comes into view.
I’ve previously been calculating Theta (below) from my weapon’s exit aperture and rotating my parent GameObject by that angle, Theta.
After drawing it out, I now understand that’s not enough since my exit aperture is on the outside radius of (what is effectively) a circle and I always end up with some “error” Theta’ (prime).
I would love a math wiz to help me calculate the angle my circle needs to rotate in order for a target to come into my field of view. My domain is 2D - everything is on the same y-plane. The center of the circle, target (x,y), radius, exit aperture (x,y) and min/max directions are all known.
consider the grey triangle: if we can solve for that bottom angle we can simply use angle addition/subtraction to get how far to rotate.
For the grey triangle we have:
the leftmost side has length of (target-center).magnitude
the lower right side has length of the (gunsposition-center).magnitude
we also have one angle for the triangle, a constant variation on the FOF angle: 180-(FOF/2)
With this information we should be able to solve the triangle completely.
You should only need the first step though, using the law of sines:
I got…
TopAngle = ArcSin( Sin(180-FOF/2)*(gun-center).magnitude/(target-center).magnitude )
BottomAngle = 180-(TopAngle+(180-FoF/2)); //angles add up to 180 for triangles