Rick Posted September 11, 2010 Share Posted September 11, 2010 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); } Quote Link to comment Share on other sites More sharing options...
Marleys Ghost Posted September 11, 2010 Share Posted September 11, 2010 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 ... Quote 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 More sharing options...
Canardia Posted September 11, 2010 Share Posted September 11, 2010 Use your own frame counter and not fmod(), then you can start the animation exactly from the frame you want. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Rick Posted September 11, 2010 Author Share Posted September 11, 2010 Yeah, I guess I was trying to avoid that. fmod seems so much cleaner. It seems like Josh shouldn't even use fmod in the tutorials if this issue exists. So there is no way to do this with using fmod? Quote Link to comment Share on other sites More sharing options...
Canardia Posted September 11, 2010 Share Posted September 11, 2010 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. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Rick Posted September 11, 2010 Author Share Posted September 11, 2010 hmm, how could you even structure something like that in code? I assume it would have to be after _frame = AppTime() / _animations[_curAnimName]->GetSpeed(); line but only when a new animation is selected and only done once. Quote Link to comment Share on other sites More sharing options...
Canardia Posted September 11, 2010 Share Posted September 11, 2010 Just use lots of if() statements and state flags to make the logic easier. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Rick Posted September 11, 2010 Author Share Posted September 11, 2010 I guess that seems messier than not using fmodf Thanks Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted September 12, 2010 Share Posted September 12, 2010 Macklebee helped ee with this issue too. Adding AppSpeed did the trick back then. http://leadwerks.com/werkspace/index.php?/topic/2563-attaching-camera-to-animation/page__p__23650#entry23650 Quote Link to comment Share on other sites More sharing options...
ArBuZ Posted September 13, 2010 Share Posted September 13, 2010 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. Quote 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 More sharing options...
Recommended Posts
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.