Combining animations

Hi there, hope your all a fantastic day. I’m not sure where to ask this so i’ve come here as my first port of call. I have a character i have made in blender, lets just say it’s a standard male human. he can run and jump, attack with a weapon etc but all individually, one at a time. I’d like him to be able to do two things at once like cast a spell while running and him do the actions for both. So he can cast while running.

So in my example to cast a spell he may only move his right arm around. For him to run he moves all his limbs and bounces up and down slightly.

What i would like to know is, is there a way to combine (in this example) the spell casting animation and the running animation so that the spell casting animation overrides the movement in the parts of the body (the right arm only) as he runs making him look like he casts the spell as he runs. I would really appreciate it if it was in C# too or just links to websites that would be helpful.

This method of combining animations would be invaluable as this is only one example of where i intent to use this “animation override” process.

This answer applies mainly to the legacy animation system.

AnimationState.AddMixingTransform() is a life-saver of a method when it comes to combining different animations into 1. Consider the following:

You want to have your character run and shoot at the same time. You have 2 base animations:

  1. Standard Walk Animation (legs / torso)
  2. Standard Shooting Animation (arms / head)

The way that I implement this is by creating an Animation Controller class that’s attached to my characters. Then in that class I apply the transforms. Since I already said that the walk animation only takes the legs and the torso, I will use:

                AnimationState walk; // AnimationState that references the AnimationState in the characters' Animation class.
                walk.AddMixingTransform(legs);
                walk.AddMixingTransform(torso);

The second you AddMixingTransform to something, all of the other weights fall off, so during this animation the rest of the body will NOT move. That being said, if you properly manage an Animation Controller, you can check things such as:

            if (moving)
            {
                // Play Movement Animation; ONLY LEGS MOVING! 
            }
            else
            {
                // Play Still Animation; ONLY LEGS STILL!
            }

            if (attacking)
            {
                // Play attack animation; ONLY ARMS AND HEAD!
            }

As you can see, using this way gives you full control over all of the animation combinations that you could ever wanna do. The controller continually updates the animations so you have to do almost nothing after applying the correct mixing transforms.

That being said,you can add as many mixing transforms as you want. Also, let’s pretend that you want the entire arm including the hand in an animation. If the hand is a child of the arm bone, then all you have to do is add the arm bone!

In Mechanim, there’s something called Body Masking which is almost the same as AddMixingTransform(). Personally, I prefer legacy because for me, text > GUI but I do suggest learning Mechanim if you want a more event-based system rather than programmatically creating one. A lot more coding with Legacy, but for me it’s worth it!