Facing Animation Problems in C++ [SOLVED]

Hello… Sorry for my bad english.

Im facing some animation problems in my c++ panda3d school assignment.
I tried to load animations using the ‘Roaming-Ralph in C++’ method. the Blackie used is just a renamed Ralph.egg (from Ralph.egg to Blackie.egg).

/*In a loading function*/
charModel[RALPH].modelFileName = "Characters/Blackie/Blackie";
charModel[RALPH].runAnimFileName = "Characters/Blackie/ralph-run";
charModel[RALPH].jumpAnimFileName = "Characters/Blackie/ralph-jump";

/*In a init function for individual characters*/
_characters[charId]->model = _WindowFramework->load_model(_WindowFramework->get_render(),charModel[charType].modelFileName);

	auto_bind(_characters[charId]->model.node(),_characters[charId]->ModelAnimControl, PartGroup::HMF_ok_part_extra | PartGroup::HMF_ok_anim_extra | PartGroup::HMF_ok_wrong_root_name);

then i tried to play the ‘Run’ animation when user is ‘Running’ and the ‘Jump’ animation when user presses spacebar.

if((_characters[iter->first]->Move_Forward || _characters[iter->first]->Move_Backward 
			|| _characters[iter->first]->Move_Left || _characters[iter->first]->Move_Right) 
			&& !_characters[iter->first]->Jump && !_characters[iter->first]->playJumpAni)
		else if (_characters[iter->first]->playJumpAni && _characters[iter->first]->Jump)
			_AnimationFSM.EnterJump(_characters[iter->first], charModel[_characters[iter->first]->id->type]);

and then i tried to play the animation according to the keypresses.
BUT, when i tried to play animations using the keypresses, SOMETIMES, the animation plays the wrong file, eg. plays the ‘Jump’ during running or plays the ‘Run’ during jumping.

I checked through my logic and i find nothing seriously wrong with it (the changing of boolean variables are not difficult), so i dont think there’s any error with the logic.

This is how i play the animation during the different key presses:

void AnimationFSM::EnterRun(Characters *_Characters)
	if (_Characters->id->type == RALPH)
		_Characters->ModelAnimControl.loop("Ralph", false);
void AnimationFSM::EnterJump(Characters *_Characters, CharDefaults _CharModels)
	if (_Characters->id->type == RALPH)
		_Characters->ModelAnimControl.loop("Ralph.1", false);
		if (_Characters->ModelAnimControl.get_frame("Ralph.1") == 13)
		{	_Characters->ModelAnimControl.pose("Ralph.1",13);	}

when i do the key presses, the text printed on the console is correct, eg printed “MOVE***” when i move around, and “JUMP***” when i presses spacebar even though the animations played are wrong.

i need urgent help in finding the solution to this problem and it will be best if there are some simple examples of playing multiple animations through key presses in C++ OR detailed documentations.

thanks in advance to all who are willing to help me :frowning:

I don’t see anything obviously wrong, though this bit concerns me:

      if (_Characters->ModelAnimControl.get_frame("Ralph.1") == 13)
      {   _Characters->ModelAnimControl.pose("Ralph.1",13);   } 

What is the goal here? To stop the jump animation when it reaches the end, instead of looping it? You should be aware that it’s possible it will completely skip over frame 13, if there happens to be a rendering chug or something, and this will never get called. If your goal is to prevent it from looping, then why not just call play() instead of loop()?


thanks for pointing that out, drwr.

i solved my animation problem. the problem is caused by the name of the tag in the model animation file.
i changed the name of the tag to RalphRun and RalphJump, and play using RalphJump instead of Ralph.1 and the problem doesnt appear anymore. Not really sure how it works, but it works. YAY! :smiley: