PixPoly

Tutorial 09

Profiles: weapons, aiming and drawing

11:24

Add weapons to your character: upper-body posture with Branch Filters, aiming and Aim Offset, switching weapons in Blueprint, showing the weapon, draw and holster animations, and locking onto a target with Strafe Focus.

Chapters

  1. 0:00Adding a weapon
  2. 0:30Body Layer: the weapon pose
  3. 1:08Branch Filters
  4. 1:23Switching weapons and adjusting the posture
  5. 2:41Full animations: It’s Own Animations
  6. 3:02Weapon in Crouch
  7. 3:58Aiming system
  8. 4:47Aim Offset
  9. 5:58Equip Weapon
  10. 6:46Placing the weapon in the hand
  11. 7:22Showing the weapon: Show Weapon
  12. 8:14Drawing and holstering: Attach Weapon to Socket
  13. 9:07Equip state and montages
  14. 10:26Multiple weapons and VFX
  15. 10:53Locking onto a target: Strafe Focus

Adding a weapon

In the Profiles tab, the plus button adds a row: this is a weapon, here a pistol. By default, its cell sets up the upper body; the legs come from the current posture — Unarmed Default in the Default column, the Crouch profile in the Crouch column.

Body Layer: the weapon pose

A weapon’s Sections tab offers the Any and Equip modes. The pose is set up in the Body Layer row: you add a layer in Clip mode, with a blend that replaces the current animation, for example Pistol Idle.

  • Driven By: not needed for a weapon, set it to Always.
  • Rise Time: the fade when entering the armed state (0.1 in the video).
  • Fall Time: the fade out (0.1).

Branch Filters

Branch Filters define from which bone the animation applies. With spine_02, its whole hierarchy plays the weapon animation; the rest — legs, pelvis, root — plays Unarmed Default. Blend Depth sets over how many bones the animation is gradually blended in: the higher it is, the smoother the transition.

Switching weapons and adjusting the posture

With the Character Factory, the mouse wheel already calls Next Weapon, which cycles through the weapons in the table. In game, an Idle animation played on the upper body alone does not work well; and a Branch Filter on the root freezes the whole body, so the character can no longer move.

  1. 1Use a run animation with the weapon (here Pistol Jog Forward), with spine_02 and a Blend Depth of 2.
  2. 2Set its Play Rate to 0: the animation stays frozen on its pose.
  3. 3Replace spine_02 with two filters, clavicle_l and clavicle_r: the character now switches properly from unarmed to armed.

Full animations: It’s Own Animations

If you have full-body animations with the weapon, right-clicking the profile’s cell lets you choose It’s Own Animations. The Sections tab becomes that of a regular profile — Forward, Strafe, Jump, Traversal, gaits, starts, stops. The The Posture’s Legs option is enough for this example.

Weapon in Crouch

Set it up by copy-paste, or use the link icon so a single setup applies to every profile. Here, Crouch has its own setup: since the legs go through the arms when walking crouched, the Run column of Pistol Crouch uses a version with the arms raised higher.

Aiming system

Right-clicking the pistol’s Default cell, then Add an Aim, adds an Aim row, valid for every profile (the link icon lets you set it per profile). Its only row, Aiming, first receives a pose: Pistol Idle in Clip, with a Branch Filter on spine_02 and a Blend Depth of 2.

In the Blueprint created by the Character Factory, aiming is already set up on the right mouse button. When aiming, the character automatically switches to Strafe.

Aim Offset

The Aim Offset lets the character aim in every direction. The base pose is in Mesh Space, with a frame of Pistol Idle as reference; you duplicate it, adjusting the spine to look left, right, up and down. The Aim Offset goes from -90 to 90 on both axes, each pose in its place.

In game, the character aims in the desired direction while moving, both standing and crouched. In Crouch, it does not switch to Strafe because no Strafe is set up in that profile.

Equip Weapon

Next Weapon cycles through the weapons; Equip Weapon equips a specific one: just enter its name in Target Profile.

To go back to unarmed, call Equip Weapon again with Target Profile set to None. In the video, the first call is wired to the key press, the second to its release.

Placing the weapon in the hand

  1. 1In the character’s skeleton, add a socket on the right hand: Weapon Socket.
  2. 2Right-clicking the socket adds a preview of the weapon so you can position it.
  3. 3In the Blueprint, add the pistol under the mesh, rename it Pistol and attach it to the Weapon Socket.

Showing the weapon: Show Weapon

The Blueprint listens to the On Weapon Changed event, called on every weapon change and which returns the new weapon. The Show Weapon function plugs into it:

  • Weapon: the weapon’s name, Pistol — copy it from the profiles table.
  • New Weapon: the new weapon returned by the event, compared with that name.
  • Sheathed: the pistol component, the mesh that is shown or hidden.

Enable Hidden in Game on the pistol so it is hidden when the game starts.

Drawing and holstering: Attach Weapon to Socket

With draw and holster animations, replace Show Weapon with Attach Weapon to Socket:

  • Weapon: the weapon’s name.
  • Weapon Mesh: the pistol component.
  • Socket Drawn: the hand socket, Weapon Socket.
  • Socket Holstered: the socket where the weapon is stowed — here Holstered Socket, created on spine_01 and placed where the character reaches for its weapon.

Equip state and montages

The node alone is not enough: you need to add the Equip state in the Data Asset. Its table accepts different animations per gait, or a single one for all of them.

  1. 1Create an anim montage from the draw animation and place it in Draw, with a Branch Filter on spine_01 and a Blend Depth of 2.
  2. 2In the montage, add the LF Profile Switch (Weapon Draw/Sheathe) notify at the moment the character grabs the weapon: the weapon then moves from the holster socket to the hand socket.
  3. 3Put the montage on the Upper Body slot, otherwise the lower body stops when the character draws while running.
  4. 4Do the same for holstering, in Sheathe.

Put the pistol back in the Holstered Socket and disable Hidden in Game: it is then visible, holstered, as soon as the game starts.

Multiple weapons and VFX

For several weapons, chain these nodes with the matching sockets: a sword on the back, for example, with a Sword profile, its equip and its aiming. Draw VFX and Sheathe VFX play a Niagara effect on weapon change, attached to a socket.

Locking onto a target: Strafe Focus

Set Strafe Focus, called while aiming with a target actor, keeps the character turned towards that target; Clear Strafe Focus releases the lock on release. Very handy for locking onto an enemy with a sword.

All tutorials