True First Person Shooter Camera with 2D Aim Offset: Body Rotation & Weapon Position Issues

I’m relatively new to Unreal (been using Unity for years now) and am currently porting an FPS system prototype I did recently in Unity to Unreal in order to make an actual game out of it. Before porting those mechanics though I’ve wanted to properly set up a true first person camera that’s seen in games like Squad, ARMA, Ground Branch, and other realistic shooters. I’m essentially aiming to achieve something like this sample I came across when researching methods to implement this sort of system.

The (currently) desired features of my camera/character setup are as follows:

  1. Use a single character mesh (for the time being until I become better at 3D modeling)
  2. Use aim offsets to realistically have the upper body rotate with movement while keeping the weapon centered. The same example from above is an example of what I mean; as the camera yaws, the shoulders move but the gun doesn’t
  3. Rotate the lower body/character smoothly when the maximum rotation of the aim offset is reached. The above example ^ illustrates this as well.
  4. Feature a bit of the ‘weapon sway/rotation lag’ that’s used to give guns weight in most FPS games when aiming around. Something like this.

To do this so far I’ve been using animations from the “HeroTPP” mesh that comes with the official ShooterGame sample. I have the camera socketed into the head of the mesh in the blueprint with “Use Pawn Control Rotation” enabled. I created a 9 directional aim offset using aim poses that came with the HeroTPP model and setup a basic anim graph for moving and using the aim offset as per the official Unreal documentation for making aim offsets. I’m also blending an idle animation with the locomotion state machine to keep the hands from bouncing everywhere while moving.

The aim offset successfully rotates the camera and gun around when moving the mouse, but the gun mesh gets offset from the center of the screen due to the way the aim offset poses are setup. Additionally, to allow full rotation using the offset, I implemented a simple system to rotate the mesh of the character when the control rotation exceeds a certain degree threshold. This rotates successfully but produces a strange ‘snap’ effect on the gun when the rotation occurs no matter the speed of the interpolation. For the weapon sway, I made a simple lerp system that uses a pivot point in the blueprint to interpolate the mesh to the mouse position with some tweakable delay, but this only works when ‘Use Controller Rotation Yaw/Pitch’ are enabled, which prevent the usage of the aim offset.

I’ve been trying to solve these issues for several days now with no luck. For keeping the gun in the center of the screen like in the desired example at the top of the post, I’ve tried blending arm animations with the aim offset which hasn’t quite worked.

Sorry if this is a long post, I just want to provide as much information as possible at the outset. If anyone can provide any sort of help to at least get me started on a path to achieving the desired result from where I’m at I’d greatly appreciate it! Although I’m very experienced with C++ I’d prefer any blueprint examples since I’m still not up to speed with Unreal’s API just yet, but C++ is welcome as well!

Thanks to anyone who takes the time to help!

Here’s links to what I’ve described:

  1. Rotation snapping problem; note the ‘snap’ effect that occurs on the gun when the camera reaches the end of the aim offset as the character rotates
  2. Weapon position problem: note how the gun rotates far too much to the side when turning left.
  3. Anim graph
  4. Character blueprint
  5. Body rotation code

I’m going to be the ■■■■■■■ suggesting you start from scratch.

What you need is a Turn In Place system that’s properly implemented to keep the root bone in the same position until the rotation exceeds the wanted rotation.
You can follow this to get that

There is a project available for download to reverse engineer.
You’ll want to change a few things but that’s what you need to have first.

When you implement this, you are going to want to blend the AimSpace and the Idle on the Pelvis bone to get your feet and your bottom top isolated from one-another. This also solves the FootIK problem you might run into when implementing this - but there’s a lot more work to go with that.

Within the videos from the links above perhaps the most notable thing is the use of curves to drive rotation.
I’m actually using curves to drive IK as well - in case you want to add that.

Second thing, you need a proper IK system for the handling of the weapon. One of your arm bones is twisting out which either means the current IK system is not correct or that the skeleton structure in use has an extra bone allowing for that bend or not within the IK chain.

Also it’s kinda vital to have this so that you can drive the gun position for lowering and raising during aiming and have it be 100% accurate to the center of the camera always offset for the iron sight that may vary from weapon to weapon.
Otherwise it’s just going to be off and your gun will need orienting to align the iron sights - bad idea.
Probably also why the issues with the rotation you are experiencing btw.

After implementing the rotation from above, your Root Yaw is going to be directly related to the orientation of the gun, since it’s essentially center camera. You just need to solve the distance on the forward vector, offset downwards by the position of the iron sight and that’s the gun hand bone location to have it smoothly interpolate on it’s own.

For shooters, socketing the camera to the head is a bad idea unless you clean up all of your animation to have a steady head. That’s why the shooter template doesn’t use a full body mesh.
You can also follow this tutorial to kinda do the same, I think he also covers a turn in place system. Either way good pointers to go through.

All in all, creating your own animations and getting the blueprint ready can take you up to a couple of weeks even if prototyping, so I know that starting from scratch sounds rough, but if you do it right once you won’t have to live with the bugs and issues. especially if you are missing the needed IK bones or have extra bones within your current skeleton…

This is all excellent, thanks so much for taking the time to write this all out! I’m not too worried about starting from scratch cause I’m already on my 4th or 5th iteration already.

About the arm bone twisting, the model I’m using from the Shooter Game example actually does have extra bones in the arms called “ForeArmRoll” that seems to be what’s causing that strange rotation. I haven’t implemented a proper IK system yet at this stage, but when I go about remaking it I’ll be sure to work on it.

Thanks for pointing me in the right direction, I’m excited to see what I learn and end up with from this experience. Do you know of any good resources related to the Unreal IK system? I’m only a little bit familiar with it at this time.

The content examples are a starting point but they can be quite horrible.
the foot one for instance is less help then a graphic explanation on what needs to be done…
the gun ones however give you the basic ideas on how to balance the gun.
the wall punch one is also a decent start for managing bone placement.

Foot IK is kinda hard. It involves some trigonometry too. Hand ik is easier unless you need to interact with a wall.

Btw, just wanted to add.
to prototype stuff before you get into the animation I just managed to successfully use the Paragon TwinBlast turn in place animations for travel (no guns, hands down).

The workflow is pretty simple. Set up retargeting with same A poses on both rigs, retarget the animations, cut them down to frame 28 so they all match.
Then add your needed metadata curves (like foot IK and the IsTurning).

In a pinch that allows you to run tests and check that the root/yaw calculations actually work as intendei since you can easily ■■■■■■ up the +180/-180 angle and what should run when since the 90deg one have to happen on a range of something to something else in order to work.
the example project has this, but the calculations didn’t work for me as I wanted 45 degree turns as well.

Now that it works I’m in anim hell for a couple hours trying to make a realistic 180 turn in place thing…

(Also the paragon animation feet arent the best example of movement for turn in place, but the curves on twinblast were inverted in the negative and they seem to work much better then what I had in the positive…)

I’ll definitely be checking all of these out now, thanks for all the info! This should all be a good starting point for me, I’ll keep this thread updated as I make progress with the character.

I’m thinking about implementing the gameplay mechanics from the prototype before rebuilding the character, but I’m now thinking the main mechanic will be dependant on having the IK setup properly later on so I might as well focus on getting that right first. The mechanic in question is a manual shotgun pumping mechanic that moves the pump up and down with mouse movement, which I could probably do with some sort of IK. Here’s a link to what that looks like in Unity for reference. Do you think this could be manipulated with the left hand attached to the pump using IK?

Depends, are you acting on the shotgun via animation or are you acting on the animation with the code?

binding the left hand IK to the shotgun pump would - regardless - move the hand to where the socket you take the position from is… the question becomes “is the hand following the shotgun or is the shotgun following the hand ?” and that’s basically what you need to work out to implement it. if you have it working on the shotgun with code you already know how much the hand slides and where…

The prototype and consequently the current plan for Unreal has the shotgun moving with a lerp in code so I could probably have it hook up to a socket and move the hand with IK from there. Like I said I’ll make updates as I go through this process.

Yes, bone IK + socket sounds like the way to go.

With a little-bit (ok, way too much) of work it’s quite possible to turn the mannequin into a somewhat realistic moving thing - though far removed from an AAA asset still due to a few glitches with the foot placement, it’s getting there.

Finally got around to reworking the system and I’ve almost gotten the desired result. I’ve got the turn in place working properly from a functional standpoint, but I’m having difficulties getting the upper and lower bodies to blend properly, resulting in the leg animations not playing all the way.

I’ve got hand IK working quite nicely. The right hand is solved on a socket on the head to prevent the model from bobbing, while the left hand is solved to the right hand effector with a transform to a socket on the pump, allowing the hands to move with the pump. The hands are balanced properly now, but I’ve run into a wall trying to get the Call of Duty style weapon offset sway I described in the original post. I’m thinking the best way to do this is to have an RInterp from the current rotation of the IK FABRIK for the right hand to the mouse movement rotator, but I haven’t been able to get the rotations to work in the desired way just yet.

I’m not able to access my computer at the moment to post images but when I’m home in a few days I will. Currently, the anim graph for the turn in place problem is as follows:

  1. Use cached pose from the basic locomation state machine into the aim offset that only has YAW plugged in, then feed this into a new cached pose called AimOffsetYaw
  2. Feed AimOffsetYaw into a Layered Blend per Bone on the pelvis, with the AimOffsetCenter acting as the pose to blend between. Blend depth is 4.
  3. Add the aim offset again but this time with only pitch attached so the previously blended idle pose doesn’t overwrite the pitch aim offset.

Is there a specific way to blend the aim offset and idle to seperate the two halves of the body? Also, when you mentioned “solve the distance on the forward vector, offset downwards by the position of the iron sight and that’s the gun hand bone location to have it smoothly interpolate on it’s own” in your first reply, was that referring to the CoD style sway? I didn’t really understand that.

Thanks again for the point in the right direction!

Hi again.

For your first question:

You can blend the base locomotion (which you might need to cache) back onto the aimoffset to achieve the same layered type of isolation as any montage playing on a slot.

you can also use the same nodea with the same blend settings as any of those tutorials to achieve the same effect by just feeding the aim on top of the locomotion again.

For your second question.
Assuming you need the gun to sway as you utilize the iron Sights, while offhand and not on a rest pose (crouched or prone usually have no sway at all)
Your sway is in a predictable pattern irl. More or less a sideways figure 8 since you continue to adjust to remain on target.
You should be feeding those values to the gun, if you have the left hand attached to it.
If your socketed gun position is affected by the right hand, you can work on that IK bone to simulate the sway.

What I was referring to was a simple solution for getting the IK bone location of where the iron sight should be - to start to interpolate towards camera center from that location on the Z axis only.
Obviously a gun doesn’t just go up and down on a z axis, but that’s the first function needed to activate any type of iron sights… getting the gun sight in the center of the screen in a way that can be adjusted on every weapon without much or any effort…

Also, if you utilize the bone like that it becomes easier to offset the Z when you apply a scope or other attachments.

Hello again,

I’ve successfully fixed the first issue with the leg animations. I didn’t even think it would be that simple of a solution, so thank you for pointing me in the right direction with that!

I’m still having trouble trying to get the weapon sway/delay to work properly with the Hand IK. I’m currently experimenting with a solution I found that achieves the exact desired result I want for the sway. It looks like this (the way the gun is offset in rotating as he moves the camera rapidly is what I mean by sway) and is explained with this code. I’m doing what I assume is the exact same thing in my code here (the issue is also visualized at that link). Basically, I’m feeding the rotation of the mouse (Camera Rotation from the example I followed) as the rotation to lerp the current hand rotation towards and setting the hand rotation in the anim graph with transform modify bones. Its producing a weird diagonal rotation when I move the mouse in a circle, which isn’t what I want. I want it to smoothly rotate just like in the example video I found.

I’d appreciate it if you could take a look at this and see if its going in the right direction. I’m continuing to tweak the variables and settings to see if I can get it to work properly, but you may be able to find an issue with the underlying implementation that I’m overlooking. Thanks again for all your help!

Ok… but… well…
you are feeding the yaw and the roll the same value. that’s already bound to go diagonally.
maybe that’s that needs to be addressed?
try unplugging Z and see what happens?

As far as what value z should have, camera z while aiming, plus iron sight offset
and Hand z when not

I tried unplugging the roll value and it still produces the same effect. However I believe I’ve figured it out now as a result of trying that. Instead of using the calculated rotation, I’m using just the “Final Rotation” value from the mouse position and that’s producing the effect I want. Thanks!

Edit: The issue is actually because of the aim offset. I managed to smooth it up to a point where it looks good though.

I’m having similar issues but they are due to the root bone rotation. Glad you got yours fixed

Hi again,

In the past week I managed to not only get the sway looking the way I want it to but also adding a “free aim” offset type of aiming featured in games like Red Orchestra 2 and Insurgency Sandstorm that’s looking really nice!

However, I’m starting to work on aiming down the sights now and running into some issues. I’m currently trying to move the camera position to a socket on the shotgun that’s placed at the rear sight area. I’m following the example shown in post #12 of this thread from one of the devs on the game Ground Branch. Its just some simple math to keep the camera lined up with the socket (my testing blueprint for this looks exactly like the pastebin blueprint link in that post), but there’s a problem where it doesn’t follow the X position of the socket no matter what its offset is. This results in the camera getting offset from the socket at the X position as the gun moves to the left and right when looking down because of the way the aim offset animations move the gun’s X location. Here’s what that issue looks like (ignore the weird rotation at the start, that’s because I was tabbed out). I know the issue isn’t caused by the free aim system because its toggled off in that example gif.

With this in mind I’m thinking the solution you suggested (using the hand bones themselves to position the gun correctly) might be the optimal way to achieve aim down sights with my implementation since it would be moving the actual bone to the center, bypassing this issue altogether. However, I’m still having a lot of trouble understanding what you mean about solving the distance on the forward vector and then offsetting it downwards to where the iron sight is located, as well as where this code should be done (Anim blueprint event graph, character blueprint, etc).

From my understanding what you were suggesting means:

  1. Let the Root Yaw Offset equal the center of the camera, or the position we want to move the hand bone to in a lerp (Position B)
  2. Get the forward vector of either the hand or the camera center; this is what I’m confused about the most
  3. Add a number that moves the camera down a bit to line up with the sights, or the sight offset
  4. The forward vector combined with the sight offset is the position we want to move from in a Lerp (Position A)

If you could help clarify this I’d greatly appreciate it. Again, I can’t stress enough how helpful and informative you’ve been, sorry if these questions feel really newbie lol. I’ll be continually tinkering with this for a while so it may be likely that I figure it out, but one of the biggest lessons I’ve learned in my time as a dev is that it never hurts to ask questions so I figured I’d post about it. Thanks again!

Hey, about the centralization of the sights in front of the camera… if you don’t mind me chiming in…

If you have a socket exactly at the aimpoint of your sight and this socket has its X axis pointing forward of the gun and Z axis pointing up (just like the Unreal camera’s X axis points forward and Z axis points up), then it’s a fact that that when this socket is perfectly aligned with the camera (in both location and rotation), its local space system is the same as the camera’s local space system, except it should be a few centimeters forward in the camera’s X axis. But X axis doesn’t interfere with alignment, it just sets distance from camera. So what this means is that if you get the hand bone’s location and rotation in *that *socket’s local space, this is actually the location and rotation that the hand bone must be in camera local space in order for the gun sight to be perfectly aligned with it. You then just have to move the hand a few centimeters in the camera’s X axis to set distance from camera.

I hope I was able to help…

Thank you so much for this, I understand exactly what you’re saying. I’ll give it a shot tomorrow as I just finished for the night (or morning rather).

With this in mind, I may now realize my problem is with the model itself. It was the first model I ever made and I did in Unity probuilder so I didn’t know the axis orientation mattered…lol

Currently the socket’s X axis arrow is pointing to the *left *of the barrel, the Y axis is pointing down, and the Z axis is pointing forward with the barrel. Here’s what it looks like.
Based on what you’ve said, this is probably causing the problem in the last gif I posted. Now that I know how to use Blender I’ll have to fix the rotation so its aligned properly and also fix that pivot point. It will most definitely throw off all of my IK offsets but I’m willing to deal with that again!

So just to clarify a bit and see if I’m following you correctly, what I essentially need to do is convert the right hand bone’s location and rotation to the local space of the shotgun sight socket and then interpolate from the hand bone’s current location to the socket’s location?

Again, thanks so much, I really appreciate the help!

More then 1 way to skin this cat. you can take it to blender and modify the bone axis. (pretty easy and probably better if you handle it in the anim BP.
you can drop a socket on the bone and rotate the socket manually to be in the “right” position.
Or you can simply remember what axis maps to what axis and code it accordingly without changing anything (though if you need to give it off to someone else and you aren’t just publishing, people might hate you for it :P)

Not exactly… get the hand bone location/rotation in the local space of the shotgun sight socket and use that to place the hand bone in the camera’s space. Remember that the key here is that sight socket space and camera space are the same.

No interpolation here, this is the position the hand bone must be keep for as long as you’re aiming down sights. You only interpolate (or should I say let Unreal blend) when you’re going in and out of that aiming state.

Thanks for the clarification! I’m at the point where I think I’ve gotten the positioning values and the offset correct, yet I’m not sure if the code I’m using to get the hand bone transform in the socket’s local space is working correctly or not. I also can’t figure out a way to get the offset values I found to apply to the socket local space variable. The issue where the gun is no longer center camera when looking up and down because of the aim offset is still persisting.

Here’s the current code I’m using for the conversion. The value being set there is sent to the Hand IK transform update variable when I press the aim button. Here’s what that looks like on its own with the issue I’m describing.The gun is almost in the right spot but I can’t seem to get the offset value to correctly add together with the variable that set in the code example I linked. Here’s what the offset looks like on its own but not in the camera’s space, which causes it to have the same issue. This is what led me to wonder if my conversion code is correct or not. I’d be very grateful if you were able to look it over and see if its correct or if I’m missing something here!

I should note; the transition between the two states has no lerp at the moment. I’m blending between the AimOffset Hip and AimOffset Iron Sights that come with the Unreal Animation Starter Pack. This issue is also not a problem anymore if I use the code from this thread’s post #12 I mentioned earlier, although I don’t think the gun is correctly aligned using this. Either way, I’m super grateful for your help! I’m so close to getting the desired effect.