How to align weapons sight with center of camera (Ironsight)

The game is a first person shooter in both C++ and Blueprint. Right now I have an aiming animation that brings the weapon to the center and aligns its sight with the center of the camera but it’s not perfectly centered and it needs adjustment on the animation.

What I heard to be a good approach is to make a socket or maybe two for weapon sight and then use IK for hands and align it with the camera, but I don’t know the math I need to do in order to achieve this. although It’s a pretty standard thing to do in a FPS game but i haven’t found any tutorials on it. so here are my questions :

  • How many sockets the weapon needs for its sight in order to align it to the camera?
  • For hands, Should i use 2 Bone IK or FABRIK for this purpose?
  • Are the hands needed to be already animated or it doesn’t matter because IK does the job?

I appreciate an overall explanation on the steps I need to do. If there is a better approach other than animating it, please explain, thanks!

Hi @THIECK, usually I try my best to answer OP question rather than suggest n alternative, but I was fortunate enough at work to have animators support the reverse IK solution so I don’t know the steps off top of my head.

However, as a workaround until somebody more knowledgeable than I can provide the actual steps. What I did on my home project was to create two sockets on the weapon, one at the blades, and another at the post (perpendicular to the z axis). The I parent my camera to a scene component at the eye socket, and when I go into iron sights, I move the camera into alignment with the two weapon sockets.

In my situation, I don’t have any clipping problems and the user is tricked into thinking their head has moved, when in reality it is just the camera. Maybe this will help for the short term until you can get the reverse IK working.

I can only comment on a very simple manual approach I’ve used before:

During the animation that transitions your weapon from hip to ADS you interpolate your arms/weapon component to a relative offset so that it ends up aligned with your crosshair.

For example, suppose when you ADS and your current animation ends up being a bit off to the right & below of your crosshair, you manually determine what the relative location of your component must be (-Y and +Z in Unreal I think) to align with the crosshair and you store that as a variable on the weapon. Then during the go to ADS animation you interpolate from (0,0,0) to this stored relative location (SetComponentRelativeLocation if I recall correctly). Naturally you also interpolate out when going back to hip firing.

The only requirements are really that your ADS animation (outside of Unreal) must ensure that the sights are horizontally aligned as adding relative rotations can be a headache. The raw position of the ADS should also at least be in the ballpark of where it should end up to make it look ok.

Refer to this video. In this case, it is a bow, not a gun. but the method is same
Align Bow and Reticle