Im trying to use multiple animations (I have Idle and Walk animations).
I create node, load model and material and then
void LoadAnimation(String name)
{
ResourceCache* cache = GetSubsystem<ResourceCache>();
Animation* animation = cache->GetResource<Animation>("Models/" + name + ".ani");
assert(animation);
AnimationState* state = model->AddAnimationState(animation);
// The state would fail to create (return null) if the animation was not found
if (state)
{
// Enable full blending weight and looping
state->SetWeight(1.0f);
state->SetLooped(true);
}
}
void Update(int animNum, float timeStep)
{
if (model->GetNumAnimationStates())
{
AnimationState* state = model->GetAnimationStates()[animNum];
state->AddTime(timeStep);
}
}
.
.
init():
mymodel.Load(blah);
mymodel.LoadAnimation("idle.ani");
mymodel.LoadAnimation("walk.ani");
update():
mymodel.Update(0, dtime); // first anim doesnt work
mymodel.Update(1, dtime); // last anim works
If I dont load walk.ani, then idle animation works. Why?
PS. I just got animations working with
void PlayAnimation(String name)
{
AnimationController *animCtrl = (AnimationController*) node->GetComponent("AnimationController");
assert(animCtrl);
animCtrl->PlayExclusive("Models/" + name + ".ani", 0, true, 0.5f);
}
but still like to know whats wrong with the first code?