So I have gotten animation blending working with animation and animation state. I have not gotten this to work with an animation controller however. If I read the docs right I create an animation state then assign that to a layer. I then use the layer in the animation controller. It does not play both animations together. Like it did before using the animation controller.
In the comments of the skeletal animation example it states:
Create an AnimationState for a walk animation. Its time position will need to be manually updated to advance the animation. The alternative would be to use an AnimationController component which updates the animation automatically.
There should be one AnimationController per AnimatedModel and not one for each animation. Telling the AC to play an animation automatically adds an AnimationState for that animation.
I thought I would post the code for someone in the future.
If you want to blend lets say a melee animation while your character or NPC is running or walking.
First create a layer.
const int LAYER_MOVE = 0;
const int LAYER_ATTACK = 1;
LAYER_MOVE has a zero value this means it is the most important animation. It is always playing. Then the LAYER_ATTACK is a one. It is only used with some logic.“This animation is not always playing”.
Then create a animation controller. AnimationController* YOURNODE->CreateComponent<AnimationController>();
Animation* combat_sword_idle = cache->GetResource<Animation>("Models/combat_sword_move_front.ani");
Animation* combat_sword_melee2 = cache->GetResource<Animation>("Models/combat_sword_melee2.ani");
Bone* root = modelObject2->GetSkeleton().GetBone("spine");
state = modelObject2->AddAnimationState(combat_sword_idle);
state->SetWeight(1.0f); This is set to 1.0 because the moving animation is the most important.
state2 = modelObject2->AddAnimationState(combat_sword_melee2);
state2->SetStartBone(root); // This animation is for upper body only. So we must set start bone.
Then in your main loop or where ever you handle the logic to choose the next animation.
swordIdle->Play("Models/combat_sword_melee2.ani", LAYER_ATTACK, true, 0.1f);
state2->SetWeight(0.75f); // This is to blend with the current moving animation.
After the animation is finsihed you must call. Otherwise animation will keep playing or character will stop if animation does not loop.
@Modanung I thought this as well. I felt like I was mixing methods. That is why I created this thread. I think my issue was the state weight. When I tell the NPC to play the melee animation and don’t set the state weight for that animation state things do not work correctly.
I did not see a way to set weights if I use just an animation controller. That is what had me confused.
Maybe the skeletal animation sample should include the method demonstrated in NinjaSnowWar, like a 50/50 spread possibly with differently coloured models. @GodMan This might be a nice opportunity for you to dip your toes into the PR stream, at your convenience of course. What do you say?