Calculate aim / lookat rotation, offset from centerline

Apologies if this has been asked, but by searching I could only find people talking about aim offset blendspaces, which aren’t my problem.

I’ve been attempting to build something of an overhead twinstick shooter and have run into a snag with accurately aiming weapons by mouse click. The problem I’m having comes down to the fact that my weapons are not centered on my actor’s origin, so I don’t know how to get the correct yaw to aim a weapon directly at the point being clicked.

Screenshots to show what I’m talking about:

The white spheres are where the mouse is clicking, while the red line is a line trace, with the collision point overlaid with a targeting reticle. I’d show my blueprints, but they’re messy and intertwined with a lot of other code, so I’ll hold off unless they’re strictly needed. I think it’s straightforward enough that that won’t be needed.

Right now, I’m using a dirt simple Find Look at Rotation blueprint node to calculate the aim yaw and pitch to feed into my blendspace to determine the aiming pose. Everything is fine, except that since the weapon is being held slightly off to the side (and above the center point of the model), it’s obviously missing the target point.

I’m totally stumped on how to fix this. I’ve tried finding pure mathematical solutions to the problem that I could write manually instead of using Find Look at Rotation, but haven’t made any progress there either. Is there some standard solution to this? I understand it’s not even an Unreal Engine specific question, but I couldn’t find anything useful elsewhere either. Presumably it would involve finding tangent lines to a circle with radius from the actor center to the gun barrel, but that line of thought hasn’t gotten me very far.

A couple of things that I’ve tried that didn’t help:

  1. I tried adding an arrow component to the actor at the approximate location of the weapon barrel in its neutral aiming pose, and calculating the look at rotation based on that. That, surprisingly, didn’t seem to generate a different rotation at all.

  2. I tried offsetting the targeted point by the local transformation of that arrow, in the hopes of tricking the find look at rotation node into “overcompensating” such that they aim at the right spot. Similar effect, where the aim didn’t change much at all.

  3. A brute force iterative correction solver. I was going to implement something like this but then realized I couldn’t because of this bug, where line traces sometimes pass through terrain. If I can’t rely on knowing where the shots will actually go when fired, I can’t correct the aim back to the correct location. Incidentally, this is also what prevents me from just using the projected impact point as the location to draw the targeting reticle. The line traces go through my terrain in many places.

Thanks for any assistance.

Why don’t you simply do the linetrace from Weapon to Mouse Location?

I have a setup in this for drawing trace from the player to where you are aiming for third person. Take a peek

Direct link to the project

Thanks! I’ll take a look at that and see if your solution can be applied to how I have this set up.

You mean firing shots from the weapon directly at where the mouse cursor is instead of straight ahead? That would fix the problem but would look strange unless I can find a way to make the character aim closer to the target point. As you can see in the images I linked, if a shot went from the barrel to where the mouse is pointing, particularly if you’re aiming up close, the shots would obviously come out of the barrel at sharp angles.