Creating and Running the Idle Animation

  • After the dwarf animator is created, we want to load an animation that was stored in the file. The ModelAnimator.Animations property contains a collection of animations loaded in from the content pipeline.
  • To create a new AnimationController to run one of these animations, we just pass in the animation.
  • To run the animation, enumerate through the BonePose objects stored in dwarfAnimator.BonePoses and set their CurrentController property to the desired AnimationController
  • For convenience, lets create a method to run an animation on all bones:
    // Add this as a new method
    private void RunController(ModelAnimator animator, AnimationController controller)
    {
        foreach (BonePose p in animator.BonePoses)
        {
            p.CurrentController = controller;
            p.CurrentBlendController = null;
        }
    }
  • Ignore p.CurrentBlendController for now.
  • Now lets create the idle animation and run it in the LoadGraphicsContent method:
    // Add this as a member variable
    AnimationController idle;

    // Add this in LoadGraphicsContent
    idle = new AnimationController(this,
        dwarfAnimator.Animations["idle0"]);
    RunController(dwarfAnimator,idle);
  • Great! We have our dwarf animated! Before we move on though, lets quickly take care of some busy work and create the rest of the controllers that we will use for our tutorial:
    // Add these as member variables
    AnimationController walk, run, nod, crouch, stayCrouched;

    // Add this in LoadGraphicsContent
    run = new AnimationController(this, dwarfAnimator.Animations["run"]);
    walk = new AnimationController(this, dwarfAnimator.Animations["walk"]);
    crouch = new AnimationController(this, dwarfAnimator.Animations["crouchDown"]);
    stayCrouched = new AnimationController(this, dwarfAnimator.Animations["stayCrouched"]);
    nod = new AnimationController(this, dwarfAnimator.Animations["nodHead"]);

Last edited Mar 8, 2007 at 2:17 PM by dastle, version 7

Comments

Micheli_Knechtel Feb 14, 2008 at 10:03 PM 
Hi,
I did the tutorial carefully and with the Dwarf model everything worked well.
But when I tried with my models, didn’t work.
Is it because there are specific ways to make the models?

johnraythomas Jun 21, 2007 at 8:35 PM 
Figured it out. I had not created the xml file yet.

johnraythomas Apr 29, 2007 at 6:12 AM 
I am getting a runtime exception that the the given key idle0 was not present in the dictionary - any idea?