Fading out an Action

I’m playing two different actions on two different layers, and I want the action playing on the second layer to fade out. I’ve avoided using the action actuator since that gave me all sorts of problems and have been using the playAction() python method instead.

The only way I was able to get the action to fade out was to continually call playAction() with increasing weight values. This actually works perfectly fine except for one problem. Whenever the action playing on the first layer changes while the second action is fading out, the armature “jumps” to a new position even though the new action on the first layer uses blendin.

My only guess as to what’s causing this is that when the first action changes, Blender immediately applies the second layer action to the new action and disregards the blendin frames.

So my question is does anyone know of a proper way to fade out an action on another layer or how to fix the problem I’m having?

Here’s a blend file so you can see exactly what I’m talking about. Space switches between the ‘up’ and ‘down’ actions and uses blendin frames. R plays the ‘right’ action.

Everything works fine until you hit space while the ‘right’ action is playing. This causes the cube to jump a little bit instead of transitioning smoothly between the actions.

Action_Fading.blend (358 KB)

Been doing a bit more testing. It seems that I can try to counteract the jumping by modifying the second layer action’s weight when the first layer action changes. However, the amount of weight I need to add seems to be a function of when the action is changed. I’m not sure how complicated it might be to figure out what function to use to get good looking results, but I’ll keep messing around with it.

I tried using a different approach of using delta key frames. They would work for what I’m trying to do, but for some reason Blender won’t let you use them on an armature in pose mode, which is what I need.

I’m really grasping at straws here. Does anyone have any suggestions?

Good news, I finally figured out the function to use.

So when you set a new action that uses blendin frames, the object’s current position becomes it’s actual position independent of other action playing on top of it. This means that the second action it now basically applied twice (at least in the first frame after the switch) which is what causes the jump.

To correct this, I had to come up with a new weight function that would compensate for this change during the blendin frames.

Here’s the function:

weight = Wn / (N/blend * (1 - Wo) + Wo)

Where Wn is the weight you would normally be using (given by whatever function you were using before), Wo is the weight you had when you first switched the action, N is the number of frames that have passed since the actions were switched, and blend is the number of blendin frames of the new action.

Note that as soon as the the blendin frames have finished (N = blend) you should stop using this function and revert to using your old function (Wn).

I know this was kind of complicated and hard to explain, but I hope it helps anyone who is interested in mixing and fading actions. Wouldn’t want you to have to go through all the trouble I did.

Hi, I’m trying to prototype a game and I’m frustrated, I can’t make it blend properly, I have this player that needs to shoot in many directions, so I moved the arm animations to layer 1, but as soon as I release the key it jumps ugly to the idle animation, I know for a smooth transition they have to be in the same layer, but it’s hard for me to follow your suggestions.

Do you have any example file ready to plug so I can adapt to my needs? some sort of an add-on that you can select which layers to blend out, that would be very helpful for beginners, anyway I will try harder, thanks for your time.

It’s been awhile since I’ve messed around with blending actions on different layers. I don’t have any add-on or general purpose code I can give you. I can show you the old code I wrote if you want, but it may just end up confusing you more.

I’ll see if I can make a simple example blend file though that demonstrates how the method I used works.

Ok thanks, your help would be greatly appreciated. :slight_smile:

Here’s a very simply example. I don’t know exactly what kind of setup you’re using or if you have multiple actions you switch between on layer 0, so I didn’t implement the complex method I discovered earlier in the thread.

This just plays a one action on layer 0. Hitting space plays an action on layer 1, and holding it down increases the action weight. When space is released, the action weight decreases. This makes the action blend in and out linearly.

If you can provide a simple blend of what your setup looks like, I can give you some more pointers.

Action_Blending.blend (427 KB)

I tried your example but it doesn’t work, when I hold the space key I don’t see any smoothing at all, btw I’m using Blender 2.66

I was using 2.63. Apparently 2.66 checks if the same action is already playing on a layer, so repeated calls to the playAction method while updating the action weight won’t do anything until the action on that layer finishes. This can be solved by using the stopAction method before calling playAction again.

Just add this line at line 18.


Now it works like a charm :slight_smile: thank you very much for your help.