How to point a weapon at a target location using IK?

First, I am pretty ignorant of IK and how it works. I’m going to start watching some more youtube stuff, but I’m hoping what I am asking is pretty simple.

So, my character is rigged with a shoulder joint, a weapon mount point and at the end of the weapon is another bone which is the muzzle. The weapon mount point and the muzzle bone are both correctly oriented (so in the case of the muzzle, the +X is the vector the bullet should travel in.)

I’ve attached a picture of my programmer art.

Now, what I would LIKE to be able to do with the magic of the IK solver is when the weapon is attached, simply take the muzzle bone and orient it so that it’s pointing at a target location, with any other bones in the arm automagically doing their thing and following along. I know this is possible, but I have no idea how to do it.

I know it would be pretty simple to just rotate the shoulder bone and have the weapon point where it should, but this is just programmer art. The actual assets may (will I hope) get more complex, with more intermediate joints. I’d really like a smart solution to this.

As is probably clear from the section, and the tag, I am doing this stuff in C++. Of course I can do whatever’s necessary in the editor, but the game is data driven so whatever I do has to support that.

I haven’t set this up set, but just looking through the code I think using a UAnimGraphNode_LookAt to connect your muzzle bone to a target location seems doable.

Did you ever resolve this?

Nope. I still assume it’s possible but no idea how to set it up. I ended up just doing the math and rotating the bones myself.