So I have a turret and I can’t figure out the angles needed to aim the thing correctly. See the skeleton of the turret below and you will know what I mean:

The red arrow is pointing to the joint that is used to aim (via skeletal controller) and the blue arrow is pointing to the joint that needs to be aimed ie this joints forward x vector needs to point to the target. Here’s a picture of how the turrent looks when properly aimed:

The red dot is the red joint being controlled and the blue dot is the blue joint being aimed. I just can’t seem to calculate theta as a function of (x,y) the targets position.

So the first thing I tried is the following steps:

- Use law of sines to get the following:

- Then the following holds:

- So pluging in and simplifying:

so you get down to a linear combination of sine and cosine which according to here (or https://en.wikipedia.org/wiki/List_of_trigonometric_identities#Linear_combinations) is equal to the following:

which reduces to:

But plugging this last equation into a blueprint the turret isn’t aiming correctly:

the “project onto plane polar coordiantes” node is doing just that (ie the brown line is the target’s projection onto the white plane). the white plane with the XYZ coordinate axis drawn is the (x,y) target position space relative to the joint used to aim (red arrow) and is rendering because the “draw debug helpers” is checked on that node.

I’m trying to find an analytical solution and not just iteratively reducing the aim error. I tried other methods but this is the simplest non-solution I could come up with. Any smarties out there that could scan the math and just tell me what stupid mistake I’m making? I would really appreciate it as this is bugging the hell out of me now. Thanks.