Creating custom casting animations

Using the Spell Casting Motion Pack, you can add custom animations to create unique casting styles.

This tutorial will take you through adding and using your custom casting style.

Most of the work is just standard Unity workflow, but I’ll walk through it.

 

Animation Setup

The first thing you’ll need is a new animation. For this example, I downloaded an animation from Mixamo. It’s a silly little spinning animation, but it will work.

Once you download the FBX, you’ll need to bring it into Unity. Ensure that the Animation Type is set to “Humanoid”.

Animation Events

Next, you’ll want to setup the animation so it looks the way you want. In this case, I went to the Animations view and set all the ‘Based Upon’ values to ‘Original’ and checked ‘Bake Into Pose’.

Finally, we need to setup the animation events. These events are what tell us when to start and stop casting. There are three key events to setup:

BeginCast – Tells the system to start running the spell flow.

CastSpell – Triggers the actual effect of the spell (like shooting a projectile).

EndCast – Tells the system to shut the spell flow down.

Where you place these animation events depends on your animation. You’ll just scrub through the timeline until you get to the spot you want.

Note: Don’t place the BeginCast event too early in the timeline or you may enter the animation after this point and the event won’t fire.

Here’s an example of what the BeginCast animation event would look like:

Notice that we always use the Function value of ‘OnAnimationEvent’. Then, we change the String value to be BeginCast, CastSpell, or EndCast.

 

Animator Setup

With the animation ready, we need to add this to our BasicSpellCasting-SM sub-state machine.

Note: This is why I always suggest making a copy of the Humanoid.controller animator controller that I provide. This way you can make changes and I won’t overwrite it during the next update.

When you drill into the BasicSpellCasting-SM sub-state machine, it’s going to look like a mess. But, trust me… it’s an organized mess. ­čÖé

Each animation style or form is represented as an animation state. That state is entered from the Any State and Stand Idle In state. It then exits out to the Spell Idle Out state and Spell Idle Transition state. The 2H_Cast_08 state is a good example to look at.

So, we need to add our new animation to the bottom of the view:

 

Then, add those enter and exit transitions that I mentioned above.

Now we need to setup the transitions so we know when to come in and out of the new animation.

If you look at 2H_Cast_08, you’ll see that we use the L0MotionPhase and L0MotionForm as conditions. The L0MotionForm value is important as that’s what we use to pick out which animation will run.

2H_Cast_08 uses L0MotionForm 22. So, we’ll use “24” for our new animation. It can be any number. We just need to remember it for later.

Now, let’s setup our transition conditions:

AnyState -> Spinning:

Stand Idle In -> Spinning:

Spinning -> Spell Idle Out:

Spinning -> Stand Idle Transition:

For both the out-going transitions, the L0MotionParameters are fixed to what you see. I use these values internally to determine if we’re heading back to the Spell Casting Idle or the regular Idle animation.

 

Spell Setup

With that done, we can now tell our spells to use this new animation for casting. Simply open the spell in the spell editor and change the Casting Style to the value we used earlier (in this case, 24).

Now when he casts that spell, he’ll use the new animation that you’ve setup.

 

Multi-Part Spells

The process I just went through works great for ‘immediate cast’ spells. What I mean is that there’s no waiting for the player to pick a target or location. The casting animation simply flows from beginning to end (like the Fire Ring Spell or Magic Missile spell).

However, if you need a multi-part spell you’ll have to break your animation into the parts. Typically these parts are: starting, waiting, and ending.

You can see that in the Standing 2H Magic Attack 05.fbx

This FBX only had one animation (mixamo.com), but I created four animation clips to support single-part spells and multi-part spells.

  • 2H_Cast_08 – Single-part spell casting animation clip (exactly what we just did)
  • 2H_Cast_08_a – Multi-part spell casting animation clip (starting)
  • 2H_Cast_08_b – Multi-part spell casting animation clip (waiting loop)
  • 2H_Cast_08_c – Multi-part spell casting animation clip (ending)

When dealing with the multi-part spells (a, b, and c clips), the animation events would be split between a (for the BeginCast) and c (for the CastSpell and EndCast).

The rest is just a matter of setting up the states and transitions like all the other spell animations.

Following 2H_Cast_08 would be a good example.

 

Leave a Reply