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 :
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!
asked Sep 11 '18 at 07:04 AM in C++ Programming
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.
Follow this question
Once you sign in you will be able to subscribe for any updates here