3 - Implementing the Aim Offset

In this step, we add the Aim Offset to our Animation Blueprint and hook it up to our existing Anim Graph.

Steps

  1. In the Content/AnimStarterPack folder, open the UE4ASP_HeroTPP_AnimBlueprint and Double-click the AnimGraph in the MyBlueprint panel.

    step3_01.png

  2. From the Asset Browser tab, drag in your Aim Offset asset.

    step3_02.png

  3. Connect the Aim Offset as shown below, then Right-click on the Yaw and Pitch pins and Promote to Variable and name them Aim Yaw and Aim Pitch.

    step3_03.png

    These two variables will be populated by where the player is aiming using their mouse and will drive the pose in our Aim Offset.

  4. In the MyBlueprint panel, jump over to the EventGraph.

    step3_04.png

  5. In the EventGraph, locate the Sequence node within the Movement portion of the script.

    step3_05.png

    Click the Add pin button on the Sequence node.

    step3_05b.png

  6. From the MyBlueprint panel, hold down Alt and drag in both the Aim Yaw and Aim Pitch and connect to Sequence node.

    step3_06.png

  7. Drag off the Cast To Ue4ASP_Character node and add the Get Control Rotation and Get Actor Rotation nodes.

    step3_07.png

  8. Drag off the Get Control Rotation node and add a Delta(Rotator) node.

    step3_08.png

  9. Connect the Get Actor Rotation to the Delta(Rotator) B Pin, then off the Return Value add an RInterp To node (and swap the connection from Current to Target).

    step3_09.png

    You can hold Ctrl and Left-click on the Current pin to drag its connection to the Target pin.

  10. Drag off the Current pin of the RInterp To node and select Make Rotator.

    step3_10.png

  11. From the MyBlueprint panel, hold Ctrl and drag in the Aim Pitch and Aim Yaw variables and connect them to the Make Rotator node's Pitch and Yaw.

    step3_11.png

  12. At the start of the Movement script, find the Event Blueprint Update Animation node and promote Delta Time X to a variable called Time and connect as shown.

    step3_12.png

  13. Back on the RInterp To node, connect the new Time variable and set the Interp Speed to 15.

    step3_13.png

    We are going to use the rotation of the character and the rotation of the player's input to create a new rotator that will limit how much the character can turn in a direction.

  14. Off the RInterp To node, add a Break Rotator and Clamp Angle of Pitch and Yaw with min/max angles set to -90 and 90 respectively.

    step3_14.png

  15. Connect the Clamp Angle from the Pitch to Aim Pitch and the Yaw to Aim Yaw.

    step3_15.png

    The Aim Yaw and Aim Pitch values that drive our Aim Offset now take into account the character's rotation, the player's current controller rotation and are clamped to prevent the character from turning too far in one direction. Without clamping the angle degrees, the character's legs could be pointed forwards while the character turns all the way around and points in the opposite direction which is probably something we want to avoid.

We are just about done with our setup, in the next step, we will tie everything together and test out our character's ability to aim.