Monday, June 27, 2011

Linking up firing animation to actual weapon firing

I've set up an AnimTree for the robot here:
AnimTree'GI_Robot.Anims.AT_CH_Robot'

For "Lethal Injection," we used an AnimNodeBlendList to link up the attack animations in the AnimTree, and then triggered the children of the AnimNodeBlendList in UnrealScript. I want to try something a little different this time.

This time I have two nodes of the type AnimNodeBlendByProperty. Each of these supposedly chooses a branch of the AnimTree based on a boolean property in the UnrealScript.

http://udn.epicgames.com/Three/AnimationNodes.html#AnimNodeBlendByProperty

Currently, I've set the AnimNodeBlendByProperty nodes check for the following booleans (which don't yet exist in the UnrealScript, I think)
1. bFiring
2. bEndingFire


bFiring is set to activate the branch of the AnimTree that holds all the firing animations when TRUE. When FALSE, it uses the branch with non-firing idle and run animations.

bEndingFire is set to activate the animation in which the robot lowers his arm after he's finished firing when TRUE. When FALSE, it uses the branch in which the robot raises its arm to get ready to fire.

Rather than use Gina's firing recoil animations, I chose to use a Skeletal Controller named GunRecoilNode linked up to the r_arm bone. I did this because somewhere within the UnrealScript, UDK already looks for and triggers GunRecoilNode whenever a character fires a weapon, and it already works well with the default Linkgun's rapidfire and sustained fire modes.

So how I think the firing animation calls would be programmed is something like this:

1. When the player presses the attack button, a boolean named bFiring is set to TRUE, which should tell the AnimTree to use the firing branch.
1a. After some delay to let the AnimTree blend from the normal to the arm extending pose, actually fire the weapon, with the GunRecoilNode triggered upon firing (which already happens).
1b. While the attack button is held down, the character sustains the arm extended pose (which is the last frame of the extending animation). The weapon will keep firing at its fire rate, triggering GunRecoilNode with each shot.
1c. If the weapon runs out of ammo while the attack button is held down, then the character switches back to the default weapon automatically and continues firing without lowering the arm.
2. When the player releases the attack button, the weapon stops firing, and a boolean named bEndingFire is set to TRUE to select the arm-lowering branch of the AnimTree
2a. After some delay to let the AnimTree finish the arm-lowering animation, set bFiring and bEndingFire to FALSE, which should set the AnimTree back to the non-firing branch.

If you think names other than bFiring and bEndingFire would be more useful, you can easily change what property the AnimNodeBlendByProperty checks for by opening AnimTree'GI_Robot.Anims.AT_CH_Robot' and selecting the nodes.

1 comment:

  1. Just for reference.

    1) bFiring has been changed to AnimBlend_FireMode
    2) bEndingFire has been changed to AnimBlend_ActiveFire (Note - its meaning is reversed, since I didn't call it AnimBlend_PassiveFire)

    ReplyDelete