#1gam Jan 2017 - Part 3
Hacking together an animation for "Watashi No Senpai Collection"

So for “Watashi no Senpai Collection,” I wanted to create an animation where the player character dives towards the Senpai like they do in anime.

QueryChan has a bunch of animations built into the asset package already, but there wasn’t any single one that appeared to be what I wanted. I considered creating my own custom animation, but I knew it was going to be too much work considering I know absolute zilch about rigging and its already the final week for this month’s #1gam. I looked through the animation list provided by QueryChan and found two animations, a “win” animation and a “laydown” animation, that I thought might work out if I chained them together.

I edited the animator to create a kind of strange animation state progression. Essentially, I want to progress through the “win” animation and “laydown” animation and play them in a sequence to provide the illusion of the character jumping forward.

Animator

If I was running in real life, I would most likely do a little hop beforehand to gather my momentum for a big jump. In terms of what I had available with QueryChan, I realized that I could simply call the “win” animation twice in quick succession to give the illusion of the little hop.

IEnumerator ExecuteDive() {
  // Set the player state to dive
  m_playerState = PlayerState.Dive;

  // move the player forward/up and animate the hop
  TriggerJump (m_hopForwardForce, m_hopUpwardForce);
  m_sdMecanimController.ChangeAnimation (QuerySDMecanimController.QueryChanSDAnimationType.HOP);
  yield return new WaitForSeconds (m_hopAnimationWait);

  // animate the actual jump
  m_sdMecanimController.ChangeAnimation (QuerySDMecanimController.QueryChanSDAnimationType.HOP);
  yield return new WaitForSeconds(m_jumpAnimationWait);

  // move the player forward/up and animate the laydown
  TriggerJump(m_fallForwardForce, m_fallUpwardForce);
  m_sdMecanimController.ChangeAnimation (QuerySDMecanimController.QueryChanSDAnimationType.JUMP_FALL);

  // wait a bit after the character reaches the floor
  yield return new WaitForSeconds(m_fallAnimationWait);

  // end the entire animation
  m_sdMecanimController.ChangeAnimation (QuerySDMecanimController.QueryChanSDAnimationType.JUMP_END);

  // reset player state back to standing
  m_playerState = PlayerState.Standing;

}

void TriggerJump (float forward, float upward) {
  m_jumpForwardForce = forward;
  m_jumpUpwardForce = upward;
  m_triggerJump = true;
}

void UpdateJumpVelocity() {
  if (m_triggerJump) {
    m_triggerJump = false;

    Vector3 forward = transform.forward * m_jumpForwardForce;
    Vector3 upward = transform.up * m_jumpUpwardForce;
    m_playerRigidbody.AddForce(forward + upward);
  }
}

Its pretty straight-forward. To create the tiny hop, I call the “win” animation while adding a very tiny forward and upward force. After the player lands, I call the “win” animation again and follow it with the “laydown” animation. Then after a small delay, I added a much larger forward and upward force for the large jump. UpdateJumpVelocity() is being constantly called in FixedUpdate(), so the private boolean triggerJump in UpdateJumpVelocity() and TriggerJump() is simply a flag to prevent premature changes in the force vectors.

In the end, I ended up with this:

It’s very rough looking and choppy. I’ll most likely tweak some of the variables as the hop distance and animation speed is really long, but overall, I’m pretty satisfied with the result.

Written by Ryan Bruce Badilla on 26 January 2017