Urho3D Wiki
Advertisement

Animations are controlled with Urho's AnimationState object.

Urho3D::AnimationState* as_run;

Your model needs to be an AnimatedModel (no StaticModel for example):

AnimatedModel* robot=node_model->CreateComponent<AnimatedModel>();

When loading your model:

Animation* ani=cache->GetResource<Animation>("Models/robot_run.ani");
as_run=robot->AddAnimationState(ani);
as_run->SetWeight(0.0f);
as_run->SetLooped(true);

You can mix animations by setting different weights, which should sum up to 1.0 (100%).

To progress an animation (each frame):

as_run->AddTime(timeStep);
// sometimes you want the animation to be progressed
// depending on stuff like velocity or engine power
as_run->AddTime(timeStep*vel.Length()/3);

The rule of all weights adding up to 1.0 is quite flexible in Urho. It's possible to blend to another animation with this:

as_stand->SetWeight(1.0);
if(!on_floor)
    as_jump->SetWeight(as_jump->GetWeight()+timeStep*5);

The jump animation is at 100% in one fifth of a second and the stand animation no longer visible. (Maybe it's not a good idea to do it like this, but it works fine in USP.)

Advertisement