How was Iron sight implemented in the First Person Shooter sample game?

Hello,

The other day I was going through the source code for first person shooter sample game. My aim was to understand how the Iron sight mode is implemented. I can see that in the character there is a bool named IsTargeting is which is toggled when I hold Right Mouse button. And within the CameraManager class, the FOV is switched to 60 from 90 when that happens.

But what I do not see is how the camera position changes. How does the camera align with the Gun’s iron sights (or scope)? Is this implemented within the character’s animation? - I can see that there is a targeting animation setup for the skeletal mesh.

Can someone help me out here?

I haven’t looked at the example, but I don’t believe the camera moves at all.

The FOV will change, and an animation likely brings the weapon mesh up to the camera to line the sights up with the center of the screen.

I’m not very good at programing, but was able to reproduce the ironsight aiming system from ShooterGame with just blueprint script.

Here’s a video that shows the results and the blueprint:

The gun is attached to the 1p mesh hand socket then the aim animation moves the weapon to the center of the screen. You have to play around with the 1p mesh rotation/translation to get it exactly center with the camera.

This video should also help you understand it:

So if I have multiple weapons which has different sizes and scope position, I have to find the right translations for all of them?

I am not very familiar with the animation stuff, but if can define two sockets on the gun, one at the scope position and one at the end of barrel, can we then use IK or something to make the character align those two sockets at runtime? Ofcourse it involves programming, but is it possible?

I suspect in most games, each weapon has it’s own paired animations to ensure the weapon is lined up correctly, this can be done quite easily within common animation packages.

You certainly could try blending animations like that, but to be honest it sounds very fiddly and time consuming to get it to feel right. I would probably animate on a per-weapon basis outside of UE4.

Thanks!

Well that clears things.

Hi W1930U7, thanks for the info on your setup, it’s excellent.
I was wondering if you wouldn’t mind sharing a screenshot of the ‘camera controls’ section that’s getting cut off at the bottom of the video?

Hey, Ik now this is VERY late, but I need to ask a question. Where did you find the ironsighting fov change in shooter game? I want to disable ironsight fov but I’m having a bit of trouble :\