Animating knockback

Jump to: navigation, search

Knockback is a tricky beast due to the combination of both animation and character controller code.

This concept has two main parts:


Animation issues

When you provide the Character Controller with a knockback instruction like move knockback (0,0,1), it sets an input called the OverridePosture to "Knockback". For Hero's Journey's animation agent script, a block interpreting OverridePosture is the first logic interpreted in the default block (sample below). This section also handles our character falling/landing animations.

From the inputs section of our AAS:

  variable OverridePosture = None, Falling, Landing, Knockback

From the default block of our AAS:

action Default   
  // Basic behavior for the whole body
  set(1) AnimAllBody
     when OverridePosture {
     is Falling:
       if ((BasePosture = Moving) and (MoveDirection = Forward)) {
         anim "fall_run_pose_loop"
         blend .75
       else {
         anim "fall_loop"
         blend 1
       hold 0
       looping true
       FreezeLastSequence true
     is Landing:
       anim "fall_landing"
       blend .1
       hold .5
       looping false
       change OverridePosture to None
     is Knockback:
       anim "combat_knockback_fall_loop"
       blend .3    
       hold 0
       looping true
       FreezeLastSequence true

Copying these should get you to the point where you can play your own knockback loop and landing (which for us happens to also be used for the fall landing). Once you get this far, the only thing missing is that you want a three part sequence (takeoff, flailing around in air loop, landing) and we currently only have two. What is needed is a transition for the OverridePosture input to play a particular action block.

transition OverridePosture {
  from None to Knockback = DoKnockback
action DoKnockback
  force(1) AnimAllBody
    anim "start_knockback"
    hold 1
    blend 0.1
    align false
    looping false
    change AlreadyTurning to False
    change CurrentMotion to Idle

At this point you will need to experiment with the action block to figure out how long you want the animation to hold, blend etc.

Other issues

Simply causing the animation to play is not sufficient to implement knockback as a real game mechanic, there are a number of other complexities that need to be handled:


While the servers have knowledge of the area geometry through the physical representation in the physics server, it is still somewhat difficult on the server to determine if a collision would have prematurely ended the knockback before the expected location is reached because the server does not run a simulation of the character controller.

For example, imagine knocking a character back over the middle of a canyon...the server does not know the character is going to fall. Since the server does not know where the character is "actually" going to end up as opposed to its predicted vector result, an alternative might be to ask one of the clients to tell us where the character is following the knockback (and verify it if necessary).


Each client has only an approximation of reality, consequently where one client may think a creature is vs another client may differ significantly. If applying a knockback impulse for a character, each client will almost certainly have the character in slightly different positions. The sledgehammer approach to fixing this is snapping the character at start and/or finish of the knockback to where the server says it should be. Remember, you must update the server's position for the character to avoid the client attempting to animate the character back to where the server thinks it should be...


AI must be smart enough to know it is being knocked back so that it can notify the interested clients to ignore movement packets and suspend AI decisions for the character pending the conclusion of the knockback. This ensures the server is not sending instructions to the client that could (depending on your animation agent code) result in different animations being played. Upon conclusion of the knockback, your AI will need to resume its normal processing. Knowing when the knockback is "concluded" requires having some idea of the distance that will be traveled and how long it takes a particular model to travel that distance using your particular knockback animations.

Personal tools