# How to calculate aim offset using IK from a rotator?

Ok so everything i can find online everyone is basically just bullshitting aim offset using blendspaces but i want to calculate it mathematically since my over the shoulder camera offset is parametric instead of static so even if i were to eyeball it changing the camera offset would just throw it off.

I am running a line trace from the center of my camera to detect the first thing it hits. Check.

I’ve created a function to track that value to a specified latency (30fps) and send the location dynamically to my animBP via blueprint interface. Check.

I’ve even figured out if i pump in that and the location of the tip of my gun to “find look at rotation” i can basically make an aim constraint for my guns rotation.

The last piece of the puzzle for me is running that rotation up the IK chain so the arm and back also rotate with it. I am not an expert at trigonometry. The only function I can see that might be useful is the Two Bone IK function but i can’t find any documentation or examples of how to use it anywhere. However, i’ve played with it and still can’t get it to work and that function outputs the location of the joint and end position, when what i want is actually the ROTATION of the root and joint to achieve the same effect.

"If you want to use Inverse Kinematics (IK) to accomplish the animation transition, you would need to set up an IK solver that calculates the desired pose for the character’s arm based on the hit location.

Here’s a rough outline of how you could use IK in Unreal Engine to calculate the desired aim offset based on the hit location:

1. Create an IK solver: You can create an IK solver by adding an “Anim Node” component to your character blueprint. There are several IK solver nodes available in Unreal Engine, including the “Aim Offset Look At” node and the “Two Bone IK” node.
2. Define the end effector and target: You can define the end effector as the bone that you want to move, and the target as the hit location. The IK solver will then calculate the desired pose for the character’s arm that aligns the end effector with the target.
3. Update the IK solver in real-time: You can update the IK solver in real-time by passing the hit location to the IK solver and calling the “Evaluate” function to recalculate the desired pose.

The “Calculate Aim Offset” function takes the local hit location as input and calculates the desired aim offset by passing the hit location to the IK solver and calling the “Evaluate” function to recalculate the desired pose. The “Apply Aim Offset” function takes the calculated aim offset as input and applies it to the character’s arm bones to achieve the desired aim animation.

Note that this is just a rough example, and the actual implementation would depend on the specific requirements of the project. You may need to adjust the IK solver node and the formula for passing the hit location to the IK solver to get the desired result."

Please don’t use chatGPT to respond to forum questions, i don’t need confidently wrong information.

I did find an actual solution that is actually incredibly simple using control rig, but it fails to account for the offset of the child relative to its parents rotation. From what i can gather, to actually get that you need to do some tricky math taking the delta of the rotator and applying the inverse transform… I mean i’m lost, i don’t fully understand it but i’ve got some messages back and forth from someone who actually somewhat knows what they’re talking about that i’ve been consulting as i try to brute force a solution and i don’t need some word salad using random blueprint names from chatGPT to confuse me even more.

Literally what the hell, someone pasting a chat GPT response to your question 10 months later had to be the most demoralizing thing ever.

The reason I am replying is I think I have a similar situation to you, and not really sure how to proceed.

The overall objective is to align the gun to point at the center of the screen.

I have the position of the center of the ‘screen’ (camera’s view, or the hit location which intersects that line), point ‘A’ let’s call it

I have an aim offset which generally moves the upper body around

The right hand is constrained with FABRIK to a transform that moves relative to the head bone. I have a vector ‘B’ from the right hand bone to the screen intersection point ‘A’.

What I am trying to do is align the right hand bone with vector ‘B’, in the hope that this causes the gun (attached to the right hand) will point at ‘A.’

The left hand is positioned by another FABRIK node, and I have no issues with this.

Anyway I would greatly appreciate discussing this topic with another person, it is tough to be going at it alone. Let me know if you want to talk as well. I am finding it very difficult to get information about this that isn’t extremely basic “Hey Guys - today’s tutorial - Left hand IK - 1 minute - Like and Subscribe” ■■■■■■ tutorials.

Here are some photos of what I have come up with. The gray arrow is vector ‘B’ and the intersecting point on the upright plate is point ‘A.’ The hand is skewed about 90 degrees and I don’t know how to correct it.