Jump to content

animation


Rick
 Share

Recommended Posts

I'm playing an idle animation and when I press a key it plays an attack animation and when that's done it goes back to idle. My issue is that when I press my key to play the attack animation it doesn't always start at the first frame of the attack animation. It seems like where it is in the idle animation is kind of where it starts in the attack animation. How can I make it so when I switch animations it'll always start at the first frame of that animation?

 

I have a map of animations that all have their start and end frames and how fast they should play.

 

void Actor::SetAnimation(string name)
{
_curAnimName = name;
_frame = _animations[_curAnimName]->GetStart();
_lastFrame = 0.0;
}

void Actor::Update()
{
       // Animation code
_frame = AppTime() / _animations[_curAnimName]->GetSpeed();
_frame = fmod(_frame, _animations[_curAnimName]->GetEnd() - _animations[_curAnimName]->GetStart()) + _animations[_curAnimName]->GetStart();

if(!_animations[_curAnimName]->IsLooping())
{
	if(_frame < _lastFrame)
		AnimationComplete(_curAnimName);
}

_lastFrame = _frame;
Animate(_mesh, _frame, 1, 0, true);
}

Link to comment
Share on other sites

My issue is that when I press my key to play the attack animation it doesn't always start at the first frame of the attack animation.

 

 

 

Yeah its a pain in the (_|_) when it does that ...

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

It's possible with fmod() also, but you need to recalculate the offset to the start frame when you want to start the animation from the first frame.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

I use such method of calculation current frame:

 

frame1+=AnimSpeed*(Engine::GetTime()-prevAnimTime)/1000.0;
if (frame1>=frameEnd)
frame1=fmod(frame1,(frameEnd-1));

model.Animate(frame1,blendAmount,curAnimation,RECURSIVE)
prevAnimTime=Engine::GetTime();

 

AnimSpeed is a speed of animation in frames per second. If it reaches the end of animation it loops to new frame from the beginning with corresponding offset.

Q6600@2.4GHz - 9600GT - 4GB DDR2@800MHz - Windows7 x64

3ds max / photoshop CS3 / C++

http://www.arbuznikov.com

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...