Archived

This topic is now archived and is closed to further replies.

horace farbuckle

odd problem w/ animating skinned meshes

Recommended Posts

Hi there everyone-- Okay, new to gameDev, just registered, and ready to post, when I get this irritating problem. I''m following along with Jim Adams'' ''Programming RPGs w/ directX'' and everything has been going fairly well. Now I''m trying to run one of his demos, which (among other things) loads a skinned mesh from an .x file, and has it run around a room. Said mesh has two animations, an idle and a walk. The idle animation works fine, and as advertised, when the mesh is idle. When walking, though, the walk animation appears to be trumped by the idle animation. That is, the creature appears to be smoothly sliding around the scene. Occasionaly a frame of the walk animation flits on screen for a split second, and is (sob!) gone. Here''s the funny part: if I change the code, so that the walk animation is used for both the walk and idle sequences, everything is fine. The creature walks around as it''s supposed to. Of course, when idle, he walks in place, but at least I''m convinced that the problem doesn''t lie with the .x mesh itself. Also, I increased the time between frames of the animations--specifically, the idle animation. If I slow the idle down to a crawl and keep the walk relatively fast, the problem is allleviated somewhat (though at that point I may as well get rid of the idle animation entirely). So, my question is: has anyone faced anything similar ("Greedy" animations)? I''ve checked the errata page for the book and it makes no mention of this... very strange. I''ve cruised through the code to the point where I''m not happy anymore, looking for the easy and the obvious. I haven''t found it. Anyone seen anything like this before? -john

Share this post


Link to post
Share on other sites
Damn, but ain''t this rare... turns out my system is too *fast*!
The problem was that which animation is active was dependent on the event queue. For any frame, if there had been a ''move'' message accquired, then the walk animation would continue... but my system was running circles around the event handler, so for most frames it would not get a move event, and hence assume that the creature wasn''t moving. Therefore it would reset the animation back to the idle case. I fixed it by polling the keyboard just before making the decision as to which animation to trigger. Works like a charm.
Too fast... hee hee!
-john

Share this post


Link to post
Share on other sites
Karl G    170
Would you be so kind as to post your changes? I have a 2.4 GHz computer so I have the same problem. Thanks! ~Karl

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
That sounds like a really sucky structure on the part of the example.

Typically, you''ll derive animation from movement, to make the feet line up with the ground and avoid sliding. Thus, once you don''t move, you''ll stop playing "walk" and start playing "idle"; then when you move, you will play "walk" again.

If the sample code renders two consecutive frames without updating physics (== movement) in between, then what''s the point of the second frame? It should pair physics update and rendering, or it should render based on some interpolation between two physics frames, so that there''s always movement if you actually move.

Share this post


Link to post
Share on other sites
Karl--
It looks sumptin'' like this:

// Move object and set new animations as needed
if(XMove != 0.0f || ZMove != 0.0f ||
m_Keyboard.GetKeyState(KEY_RIGHT)
|| m_Keyboard.GetKeyState(KEY_LEFT)
|| m_Keyboard.GetKeyState(KEY_UP)
|| m_Keyboard.GetKeyState(KEY_DOWN))

...this goes right before deciding which animation to set. In the original code, all it checked for was whether the x or z coords had been changed by a keypress. Really all you need to do is check if one of the arrow keys is down, as the above does. Hell, you could get away with checking if *any* key is down, in this case.

... this was the ''3din2d'' example, btw. Hope this helps.

-john

Share this post


Link to post
Share on other sites