Clackdor Posted October 12, 2011 Share Posted October 12, 2011 So, I'm trying to get it so that when I hit key 1, my chick swings her sword 1 time and is ready for another attack. Unfortunately, he behavior seems somewhat erratic, sometimes not completely the animation. Sometimes starting the beginning part of the animation, then stopping. if (KeyHit(KEY_1)){ //Attack 1 if (state == 0) { state = 1; starttime = AppTime();} else {nextstate = 1;}} animationlength = (100*(frameend-framebegin))/animationspeed; if ((AppTime() - starttime) > animationlength) { state = nextstate; nextstate = 0; starttime = AppTime();} frame=animationspeed*AppTime()/100; frame=fmodf(frame,frameend-framebegin)+framebegin; Animate(mesh,frame,0.40,0,true); Quote Link to comment Share on other sites More sharing options...
Rick Posted October 12, 2011 Share Posted October 12, 2011 I sort of think the animation example LE comes with a pretty poor or more perhaps it's just to get the general idea of how to animate in LE but not how to animate in the best way for an actual game. I find it much easier to use an approach where I increase my frame by a given amount (1 in my example) at a given interval. To add on to that idea, when getting into blending I've found (from help of others on this board) to "play" all your animations (or just a set of them) all the time BUT modifying the blend value to get nice blending between them. Again, what I do with this is have a timer to increase the blend value to the animation I want played and decrease the blend value to the current animation until it's 0. These ideas make it easier to work with animations however it's more complex to setup so guessing that's why Josh didn't go that route. Quote Link to comment Share on other sites More sharing options...
Clackdor Posted October 12, 2011 Author Share Posted October 12, 2011 Thanks Rick. I changed to an iterative method and it's behaving. Any links to examples of the blending method? I assume that each animation would be its own sequence so they could be played at the same time. Quote Link to comment Share on other sites More sharing options...
Rick Posted October 12, 2011 Share Posted October 12, 2011 No example links that I can think of. I'm out of town starting tomorrow and pretty busy tonight but if I remember I can show you what I do. To explain it: Create an animation class that stores things like: name, currentFrame, startFrame, endFrame, loop, blend, speed 1) Create instances for each animation and store them in a list probably by character or whatever 2) Loop through each animation every frame calling the Animate() method on them (sort of). However at the start of the function that does this you can check for a blend value of 0 for that specific instance and bail out since a blend of 0 wouldn't show anything anyway there isn't much point in running the frame increase code. 3) Make a method to change animation. This would start a timer on the old animation to have it's blend value decreased, and start a timer on the new animation to have it's blend value increased. 4) ?? 5) Profit That's all you have to do. It all becomes about the blend value for the animation then. Some people will have a list of just the animations they are blending and only call the function that will call Animate() on those, but I just use my master list so I don't have to screw around with another list. I add that blend check so if it's an animation that isn't one of the 2 I'm blending out of or in to it just skips the rest of the frame increasing because it's meaningless anyway so that helps reduce the overhead. If there is such a hit of going into the function and bailing out right away each frame I just eat it to save myself having to manage a separate list of animations. I've added some other things like events for animations. Like an OnComplete or even an arbitrary event that I pick which frame to call it on. I do this for things where I want another thing to happen at a certain point in an animation. Helps it look more real. ie. on frame 213 the sword would be hitting the target so fire an event to do some code to see if it's a hit/miss/dodge, how much dmg and if it's a hit then have the target play it's hit animation. Quote Link to comment Share on other sites More sharing options...
cassius Posted October 12, 2011 Share Posted October 12, 2011 I sometimes get one animation interfering with another and don.t understand blending. If the official tuts on anims are not good could someone show us an example that DOES work properly and which could be translated to Bmax. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Naughty Alien Posted October 13, 2011 Share Posted October 13, 2011 ..LE examples are fine..what you need is actually animation manager where you will just use simple commands sent to manager and manager will perform all those things for ya..its very hard to control things on the way your code shows..i mean, you may end up with tens of different animations, and some may be linked or grouped (idles, or attack/die animations, etc), then such hardcoded control is not way to go.. @ Cassius ..if you have some character of interest, send me that character, with correct frame ranges and ill compile small animation manager module for you (bmax) so you can control your animations very easy.. Quote Link to comment Share on other sites More sharing options...
Clackdor Posted October 13, 2011 Author Share Posted October 13, 2011 ..LE examples are fine..what you need is actually animation manager where you will just use simple commands sent to manager and manager will perform all those things for ya..its very hard to control things on the way your code shows..i mean, you may end up with tens of different animations, and some may be linked or grouped (idles, or attack/die animations, etc), then such hardcoded control is not way to go.. This is what I'm thinking, too. This is my first experience with animations and the code you see is my first attempt. Read my blog post over in that section of the website to see what that code results in. Instead of trying to code something from scratch right now, though, I'll probably just read and research (I spend a lot more time reading than coding anyway). Also, I'll want to add audio events into the animations (grunts, sword clashes, unsheathing, etc.) in the animations control. If I can just put Player::Die(); or Player::Skill1(); that would be awesome. Links to examples would be very much appreciated. Quote 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.