Game Development Community

BUG in Animation Component Code

by John Kanalakis · in Torque X 2D · 12/25/2007 (3:21 pm) · 7 replies

The T3DAnimationComponent has a very simple bug, that's more of a 30 second feature request.

Please change the T3DAnimationComponent.cs file line 1119 from:

List _animations;

To:

List _animations = new List();

I know it's simple and trivial, but it is completely impossible to setup animations in code without this code change, due to a null reference. Presently, animations can only be setup in XML. I'm labeling this as a small bug because anything that you can do in XML, you should be able to do in code - and in the current state, that can't be done. And, it's being done in the class' CopyTo() method.

Thank you,

John K.

About the author

John Kanalakis is the owner of EnvyGames, an independent game development studio in Silicon Valley that produces games and tools for Xbox 360, Windows, and the Web.


#1
12/30/2007 (7:21 am)
I ran into this as well, but I hit shortly afterwards a null reference on Owner, may I ask how exactly you are setting up your animations in code?


Thanks,
-- Matt
#2
12/30/2007 (12:36 pm)
Hi Matt, I'm still working on that. So far, 3D animation has been the hardest part for me to figure out in Torque X. Writing custom shaders is even proving to be much easier. But here's what I have so far...

public void SetupPlayerAnimation(T3DAnimationComponent componentAnimation)
{
    //Create the Track Animation object
    TSTrackAnimation animationTrack = new TSTrackAnimation();
    animationTrack.SequenceName = "Look";
    animationTrack.ThreadName = "LookThread";
    animationTrack.TrackInterfaceName = "lookHeight";
    animationTrack.Setup(componentAnimation);
    componentAnimation.AddAnimation(animationTrack);
 
    //Create the Animation Finite State Machine
    AnimationFSM animationFSM = new AnimationFSM();
    animationFSM.StartState = "StartState";
    animationFSM.Setup(componentAnimation);
 
 
    //Create the individual animation objects and add them to the FSM
 
    //Idle Animation
    TSAnimation animationIdle = new TSAnimation();
    animationIdle.ThreadName = "ActionThread";
    animationIdle.SequenceName = "root";
    animationIdle.Name = "Idle";
    animationFSM.AddAnimation<MoveAnimationState>(animationIdle);
 
    //Forward Animation
    TSAnimation animationForward = new TSAnimation();
    animationForward.ThreadName = "ActionThread";
    animationForward.SequenceName = "run";
    animationForward.Name = "Forward";
    animationFSM.AddAnimation<MoveAnimationState>(animationForward);
 
    //Fall Animation
    TSAnimation animationFall = new TSAnimation();
    animationFall.ThreadName = "ActionThread";
    animationFall.SequenceName = "fall";
    animationFall.Name = "Fall";
    animationFSM.AddAnimation<MoveAnimationState>(animationFall);
 
    //Back Animation
    TSAnimation animationBack = new TSAnimation();
    animationBack.ThreadName = "ActionThread";
    animationBack.SequenceName = "back";
    animationBack.Name = "Back";
    animationFSM.AddAnimation<MoveAnimationState>(animationBack);
 
    //Left Animation
    TSAnimation animationLeft = new TSAnimation();
    animationLeft.ThreadName = "ActionThread";
    animationLeft.SequenceName = "side";
    animationLeft.Name = "Left";
    animationLeft.TimeScale = -1.0F;
    animationFSM.AddAnimation<MoveAnimationState>(animationLeft);
 
    //Right Animation
    TSAnimation animationRight = new TSAnimation();
    animationRight.ThreadName = "ActionThread";
    animationRight.SequenceName = "side";
    animationRight.Name = "Right";
    animationFSM.AddAnimation<MoveAnimationState>(animationRight);
 
    //Land Animation
    TSAnimation animationLand = new TSAnimation();
    animationLand.ThreadName = "ActionThread";
    animationLand.SequenceName = "land";
    animationLand.Name = "Land";
    animationFSM.AddAnimation<MoveAnimationState>(animationLand);
 
    //Dead Animation
    TSAnimation animationDead = new TSAnimation();
    animationDead.ThreadName = "ActionThread";
    animationDead.SequenceName = "land";
    animationDead.Name = "Dead";
    animationFSM.AddAnimation<MoveAnimationState>(animationDead);
}

There's still more to post, I need to find the rest of the files... like how to change the FSM state to trigger the animation. I just need to find the files and post back. I have about 50 different TorqueX projects on my laptop that test out different areas of Torque X. ;)

John K.
#3
12/31/2007 (10:45 am)
Thanks, your forum posts are showing me a lot more than I would have been able to figure out with my limited experiments with Torque X.

I still haven't figured out how to make the animation play either after toying with FSM's and States last night.

I see you are using a MoveAnimationState for your FSM, I got to the point last night where it started demanding all of the FPS components that would normally be attached to a player-- Control, Health, etc. And So I created my own AnimationState which always returned "Idle" from Execute, but that hasn't helped getting the animation to play, my boombot still stands still.


--Matt
#4
12/31/2007 (4:18 pm)
Thanks for the nice words, Matt. Again, 3D animation has been the most trouble for me so far. I can pull it off with XML (using the FSM structure and input controllers), but my goal is to get it working in code with as little overhead as possible. Afterall, if you have a mesh with animation data baked into it, how hard can it possibly be to call a "play animation" function ;)

Anyway, I promise to post back with the results. Hopefully within the next couple of day. But, if you find the answer first, please feel to share your findings.

Happy New Year !!!

John K.
#5
02/03/2008 (4:57 pm)
@John,

Do you have any simple example code for calling the baked in animation of a DTS in an XML file?

Thanks,
Jeff
#6
10/07/2009 (11:51 pm)
Where you ever able to get a simple animation method created?

public class Game : TorqueGame, IAnimatedObject
    {
        public void UpdateAnimation(float dt)
        {
            if (_currentAnimation != null)
            {
                _currentAnimation.Thread.AdvanceTime(dt);
            }
        }

        enum CurrentAnimationPlaying
        {
            Idle,
            Forward,
            Back,
        }

        TSAnimation _currentAnimation;
        CurrentAnimationPlaying _currentAnimationPlaying;

        public void CreateDaniel()
        {
            RigidCollisionManager rigidManager = TorqueObjectDatabase.Instance.FindObject<RigidCollisionManager>("RigidManager");

            //create the simple torque object   
            TorqueObject objPlayer = new TorqueObject();
            objPlayer.Name = "PlayerObject";

            //create the render component   
            T3DTSRenderComponent componentRender = new T3DTSRenderComponent();
            componentRender.SceneGroupName = "PlayerObject";
            componentRender.ShapeName = @"datatank.dts";
            objPlayer.Components.AddComponent(componentRender);

            //create the scene component
            T3DSceneComponent componentScene = new T3DSceneComponent();
            componentScene.SceneGroup = "PlayerObject";
            componentScene.Position = new Vector3(10, 100, 75);
            objPlayer.Components.AddComponent(componentScene);

            // create shadow
            T3DBlobShadowCasterComponent componentShadow = new T3DBlobShadowCasterComponent();
            componentShadow.SceneGroupName = "PlayerObject";
            objPlayer.Components.AddComponent(componentShadow);

            // Physics
            //T3DRigidComponent componentPhysics = new T3DRigidComponent();

            // Add the animation component
            T3DAnimationComponent componentAnimation = new T3DAnimationComponent();
            componentAnimation.SceneGroupName = "PlayerObject";
            objPlayer.Components.AddComponent(componentAnimation);

            //Forward Animation
            TSAnimation animationForward = new TSAnimation();
            animationForward.ThreadName = "ActionThread";
            animationForward.SequenceName = "run";
            animationForward.Name = "Forward";
            componentAnimation.AddAnimation(animationForward);

            _currentAnimationPlaying = CurrentAnimationPlaying.Forward;
            _currentAnimation = (TSAnimation)componentAnimation.GetAnimation("run");
            _currentAnimation.Play();

            //register the object
            TorqueObjectDatabase.Instance.Register(objPlayer);
        }
    }

Trying to get as simple of animation rendering as possible?
#7
10/30/2009 (4:16 pm)
Anyone Please?