Creating an Aim Offset
In this guide, we will create an Aim Offset, which is an asset that stores a blendable series of poses to help a character aim a weapon. We will take an animation sequence and chop it up into usable poses for an Aim Offset, get the player's pitch/yaw location of the mouse and use that to determine which blended pose to use so that the character moves and aims in the location of the mouse (with some restrictions) as seen in the example below.
For this guide, we have created a new project using the Blueprint Third Person template with Starter Content enabled.
We are also using the Animation Starter Pack which is available for download for free via the Marketplace.
Once downloaded, you can add the Animation Starter Pack to your project via the Add To Project button from the Launcher.
Creating Aim Poses
In this section, we will create the aiming poses needed for the Aim Offset by chopping up an animation sequence.
With your project open, inside the Content Browser under the Game/Blueprints folder, open the MyGame Blueprint.
Under Default Pawn Class, click the dropdown menu and select the ASP_Character.
Compile and Save then close the Blueprint.
In the Content Browser open the Game/AnimStarterPack folder.
Click the Create button and create a folder called AimPoses.
Drag the Aim_Space_Ironsights asset onto the AimPoses folder and select Copy.
This is the animation sequence that contains a range of motions for aiming a weapon that we will chop up into poses.
Inside the AimPoses folder, with Aim_Space_Ironsights selected, press Ctrl+W to duplicate it and name it Aim_Center.
Open the Aim_Center asset, click the Pause button from the playback controls, then click the ToFront button.
This will make sure that the animation is currently sitting at frame 0 of 102.
Right-click on the scrub bar in the timeline, then choose the Remove from frame 1 to frame 102 option.
Right-click on the scrub bar in the timeline again, then choose the Remove from frame 1 to frame 2 option.
You should have a timeline that looks like below.
With this, we now have a single frame containing a pose we can use in our Aim Offset.
Click Save then close the Aim_Center animation.
In the AimPoses, with Aim_Space_Ironsights selected, press Ctrl+W to duplicate it and name it Aim_CenterDown.
Open Aim_CenterDown, make sure it is on frame 0, then click the ToNext button and go to frame 20.
The character will now be aiming downward in the viewport, which is the pose we want to use for aiming down.
Right-click on the scrub bar in the timeline, then choose the Remove frame 0 to frame 19 option.
Depending on where you right-click on the scrub bar, the frame range may be different, just make sure the character is aiming down.
Right-click on the scrub bar in the timeline again, then choose the Remove from frame 1 to frame 83 option.
Your Aim_CenterDown animation should now look like below in the timeline with the character aiming down in the viewport.
In the AimPoses, with Aim_Space_Ironsights selected, press Ctrl+W to duplicate it and name it Aim_CenterUp.
Open Aim_CenterUp, make sure it is on frame 0, then click the ToNext button and go to frame 10.
Right-click on the scrub bar in the timeline, then choose the Remove frame 0 to frame 10 option.
Again, the frame range may be slightly different depending upon where you right-click, just make sure the character is aiming upwards.
Right-click on the scrub bar in the timeline again, then choose the Remove from frame 1 to frame 92 option.
Your Aim_CenterUp animation should now look like below in the timeline with the character aiming up in the viewport.
Now that you have created an Aim Center, Aim Down and Aim Up pose; repeat the process cited above to create an Aim Left (Center, Up, and Down) and Aim Right (Center, Up, and Down). You can use the table below to identify suggested keyframes to start from and the keyframes to remove to generate your poses.
Duplicate the Aim_Space_Ironsights asset each time and create each of the remaining poses based off the table below.
Anim Name Start At Keyframe Remove Frames 1 Remove Frames 2 Aim_LeftCenter 35 0 - 34 1 - 68 Aim_LeftUp 40 0 - 39 1 - 63 Aim_LeftDown 50 0 - 49 1 - 53 Aim_RightCenter 65 0 - 64 1 - 38 Aim_RightUp 71 0 - 70 1 - 32 Aim_RightDown 81 0 - 80 1 - 32 For each animation, be sure to start at the suggested Start At Keyframe frame, then Right-click on the scrub bar and Remove Frames 1, Right-click on the scrub bar again and Remove Frames 2. Each of your animations should be a single frame with the character aiming in the direction of its corresponding name.
When you have created each, your AimPoses folder should have several poses in it for each aiming direction.
Open the Aim_Center animation from the AimPoses folder.
In the Anim Asset Details window under Additive Settings, click the No additive option and change it to Mesh Space.
For an animation to be compatible with an Aim Offset, it must be set to use an Additive Anim Type of Mesh Space.
Click the Reference Pose option and change it to Selected animation frame.
Click the None dropdown option, then search for and select the Idle_Rifle_Ironsights animation to use as the Base Pose.
In the Asset Browser, one-by-one, open each aim pose and repeat steps 22 - 24.
Make sure that each is set to use an Additive Anim Type of Mesh Space and the Idle_Rifle_Ironsights Base Pose is assigned.
Once you have done so, return to the Content Browser and click the Save All button.
Creating the Aim Offset
With the poses created, next we will create the Aim Offset asset and set up the poses for blending.
In the Content Browser, click the Create button, then under Animation select the Aim Offset.
In the Pick Skeleton window, make sure to select the HeroTPP_Skeleton that is in the Game/AnimStarterPack/Character folder.
Name the Aim Offset, Hero_AimOffset then open it up.
Inside the Hero_AimOffset, in the Anim Asset Details panel, click the Preview Base Pose under Additive Settings.
In the pop-up window, search for and add the Idle_Rifle_Ironsights animation sequence.
This will be used as the Preview Base Pose to blend from once we start adding our aim poses to the Aim Offset.
In the Hero_AimOffset window (center window), under Parameters, enter the parameters shown below.
Set the X Axis Label to Yaw and Y Axis Label to Pitch, then set both Axis Ranges to -90 to 90 and click Apply Parameter Changes.
For information on how Blend Spaces work (which are what Aim Offsets are based upon), see Blend Spaces.
In the Asset Browser, search for Aim, then drag the Aim_Center animation onto the graph in the center position as shown below.
Drag the Aim_CenterUp to position 1 and Aim_CenterDown to position 2 cited below.
Drag the Aim_LeftCenter to position 1 and Aim_RightCenter to position 2 cited below.
If you move your mouse within the grid now, the character will start to aim and blend between the poses.
Add the Aim_LeftUp (1), Aim_RightUp (2), Aim_LeftDown (3) and Aim_RightDown (4) poses to finish the Aim Offset.
The Aim Offset is now set up, now we need to hook it up for use within our Animation Blueprint.
Implementing the Aim Offset
In this section, we will implement the Aim Offset inside the character's Animation Blueprint, so it is a part of their animation set.
Inside the Content Browser under Game/AnimStarterPack/Character, open the ASP_HeroTPP_AnimBlueprint.
This is the Animation Blueprint that is assigned to the playable character and governs the logic for the character's animations.
For information on how Animation Blueprints work, see the Animation Blueprints documentation.
Inside the Animation Blueprint, in the lower center window, click the MyBlueprint tab, then Double-click the AnimGraph.
This will open the Anim Graph tab which is where we will implement our Aim Offset.
In the MyBlueprint window, click the Add Variable button to create a new variable.
In Details panel to the right, change the Variable Name to PlayerAimYaw and the Variable Type to a Float.
In the MyBlueprint window, click the Add Variable button again and name the new variable PlayerAimPitch (also a Float).
Click the Asset Browser tab, then search for Hero and drag the Hero_AimOffset into the graph.
Click the My Blueprint tab, then drag the PlayerAimYaw variable onto the Yaw of the Hero_AimOffset node.
Also drag the PlayerAimPitch variable onto the Pitch of the Hero_AimOffset node.
Connect the Locomotion pose to the Base Pose of the Hero_AimOffset, then the out pose to the Result.
This will take whatever the pose is from the Locomotion State Machine, then apply the Aim Offset on top of it as the final pose.
Click the MyBlueprint tab in the lower center window, then Double-click the EventGraph to open it.
This will open the Event Graph tab which is used to keep the character animations updated with what is occurring in-game.
In the EventGraph, locate the Sequence node in the graph.
Click the Add pin button on the Sequence node.
From the MyBlueprint window, hold Alt and drag the PlayerAimYaw variable into the graph.
This will create a Set node which we will use to get the player's current Yaw and determine the blend points on the Aim Offset.
Hold Alt and drag in the PlayerAimPitch, then connect both to the Then 2 pin of the Sequence node.
Drag off the As ASP Character pin of the Cast to ASP_Character node and search for and add the Get Control Rotation node.
Repeat the previous step, but search for and add the Get Actor Rotation node.
Right-click in the graph and search for and add the Delta (Rotator) node.
Connect the Get Control Rotation to the A and the Get Actor Rotation to the B of the Delta(Rotator) node.
Right-click in the graph, search for and add the RInterp To node.
Right-click in the graph, search for and add the MakeRot (Make Rotation) node.
Drag-and-drop the PlayerAimPitch and PlayerAimYaw variables onto the Pitch/Yaw of the MakeRot node.
Connect the nodes as shown above.
This will get the current value of PlayerAimPitch and PlayerAimYaw and smoothly transition to the player's actual Pitch/Yaw.
At the beginning of the Movement section, drag off Delta Time X of Event Blueprint Update Animation and Promote to variable.
We will use this to store a variable to Delta Time for use with our RInterp node.
Name the variable Time and connect as shown below.
Drag-and-drop the Time variable onto the DeltaTime pin of the RInterp To node and set Interp Speed to 15.
We have assigned a reference to time and set the speed at which to move from the player's old pitch/yaw location to their new location.
Drag off the Return Value of the RInterp To node and add the Break Rot (Break Rotation) node.
Off the Pitch, add the Clamp Angle node.
Set the Min Angle to -90 and the Max Angle to 90.
Copy/Paste the Clamp Angle node and connect it to the Yaw, then connect both to the PlayerAimYaw and PlayerAimPitch nodes.
The logic is setup for getting/using the player's pitch/yaw with our Aim Offset, just a few more things to finish up.
Finishing Up
In this final section, we will change the default idle pose and update Character Blueprint in order to use the Aim Offset correctly.
Continuing from the previous section, click the MyBlueprint tab then Double-click Locomotion to open the graph.
Double-click the Idle state inside the Locomotion graph.
From the Asset Browser, drag in the Idle_Rifle_Ironsights and connect it to the Result pin.
You can leave the Play Idle_Rifle_Hip node if you want to return to this later.
Compile and Save then close the Animation Blueprint.
Inside the Content Browser under Game/AnimStarterPack/Character, open the ASP_Character Blueprint.
On the Defaults tab, search for Rotation, then uncheck the Use Controller Rotation Yaw option.
This will prevent the character from automatically turning to the location of the Controller's yaw.
Click the Graph tab, then find the Crouching section and replace the InputAction Crouch node with a C Key Event.
This will remove the yellow warning sign on the compile button in the upper left corner of the window since the project does not have an Action Mapping for Crouch by default, we are going to use the C button to crouch (you can use any Key Event you wish for this).
Compile and Save then close the Blueprint
In Engine Version 4.8 and higher, you will need to remove the ThirdPersonCharacter from your level. This can be done by locating the ThirdPersonCharacter within the Scene Outliner of the Editor Viewport, clicking on the ThirdPersonCharacter, and pressing delete.
This needs to be done due to the ThirdPersonCharacter being automatically possesed within the level.
Be sure to Save the project once removing the ThirdPersonCharacter from the level.
Click Play from the Main Editor Toolbar to play the game.
When you play in the editor, the character will now aim while stationary and will react to mouse movement, pointing in the direction of your mouse. There are some restrictions in place that prevent the character from turning and facing backwards while the mouse is behind them as well and while the character is jogging, moving the mouse also turns the character's torso in the direction you are pointing.
You can take this a few steps further by allowing the character to aim in a direction and play a shooting animation in that direction and (or) allow the character to play a shoot animation while moving in a direction or crouching by taking a look at the Using Additive Animations How To page to learn about blending multiple animations together. Or, you can take a look at Skeletal Mesh Sockets for examples on how to attach an weapon to the character's hands now that they can aim.