Jump to content

Animation Blending


Krankzinnig
 Share

Recommended Posts

Just wanted to start off saying I have read the animation tutorial pdf countless times and cannot figure out how the blend works with idle. I don't get the blend += 0.01 part. I get what it does but I don't get where the value comes from and how I can set up to 48 different animations. I want to wrap this up into a class so I need to know what values I can increment by for blend. Here is some of my existing animation code:

 

               if(KeyDown(KEY_W) && !KeyDown(KEY_LSHIFT))
	{
		MoveSpeed = 1.5f;

		if(HasSword)
		{
			// Animate the Walk Forward sequence with sword
			FrameBegin = 600.0f;
			FrameEnd = 640.0f;
			Frame = AppTime() / 100.0f * 2.0f;
			Frame = fmodf(Frame, FrameEnd - FrameBegin) + FrameBegin;
			Animate(Player, Frame, 1.0f, 0, true);
		}

		else
		{
			// Animate the Walk Forward sequence
			FrameBegin = 10.0f;
			FrameEnd = 50.0f;
			Frame = AppTime() / 100.0f * 2.0f;
			Frame = fmodf(Frame, FrameEnd - FrameBegin) + FrameBegin;
			Animate(Player, Frame, 1.0f, 0, true);
		}
	}

	else if(KeyDown(KEY_S) && !KeyDown(KEY_W) && !KeyDown(KEY_A) && !KeyDown(KEY_D))
	{
		MoveSpeed = 1.3f;

		if(HasSword)
		{
			// Animate the Walk Backward sequence with sword
			FrameBegin = 645.0f;
			FrameEnd = 685.0f;
			Frame = AppTime() / 100.0f * 2.0f;
			Frame = fmodf(Frame, FrameEnd - FrameBegin) + FrameBegin;
			Animate(Player, Frame, 1.0f, 0, true);
		}

		else
		{
			// Animate the Walk Backward sequence
			FrameBegin = 55.0f;
			FrameEnd = 95.0f;
			Frame = AppTime() / 100.0f * 2.0f;
			Frame = fmodf(Frame, FrameEnd - FrameBegin) + FrameBegin;
			Animate(Player, Frame, 1.0f, 0, true);
		}
	}

AMD Phenom II X4 B55 3.20 GHz - 8.00 GB Patriot Gamer Series RAM - AMD Radeon HD 6800 Series 1 GB GDDR5 - Windows 7 Professional 64 Bit

Link to comment
Share on other sites

I don't think the animation tutorial is very good. It's pretty limiting as you've found out. I don't use fmodf() for animations. Instead I created a timer class and use the old 2D style of animation where you inc frame by a timer and if it's past the frame loop it back.

 

Then to handle blending I personally just run Animate() on every registered animation (sort of). The difference would be the blend value. Most of the animations will have a blend of zero and pretty much only 2 animations would have a blend value when going from 1 to another. Other people store more of an active list of animations and play all the animations on the active list. That's the more efficient way but then you are managing that list, so for my demo's I just play everything I registered.

 

So for example here is what I do in my player class that has the following animations

 

Animations["idle"] = new Animation(this, "idle", 0.0F, 200.0F, true, 40);
Animations["run"] = new Animation(this, "run", 322.0F, 341.0F, true, 40);
Animations["jump"] = new Animation(this, "jump", 379.0F, 410.0F, false, 16);

 

So now I've registered 3 animations with this player. I generally set "idle" as the active animation right away after initializing the animations.

 

Each animation object has it's own blend value. Very important thing to note as when looking at the tutorials it only uses one so your brain might not be in that mode :)

 

The Update() method of the Animation objects is called for every animation you registered every frame. What I do is right away say if blend <= 0.0 then just return right away to save time since there is no sense in trying to playing an animation with a 0 value blend.

 

When you switch animations the idea is to start a process for the old animation object to start decreasing it's blend value which would most likely have been 1 since it was active and player. At the same time you tell the new animation to start increasing it's blend value. These decrease and increase is done at a given interval you see fit. Again I activate timers inside the animation object to increase/decrease every so often. Internally once the blend value reaches it's max/min it'll stop it's timer. Now you've just blended from 1 animation to the next.

 

So when talking about managing a list of active animations I don't do it but you will notice that I will then have the overhead of each animation object calling it's Update(). Since I have a blend check right away and return the overhead is still pretty small, but if you managed an active animation list, you would be looping through less animation objects because you would be managing this list and adding/removing animation objects as they come in and out of having a blend value > 0. I just accept the overhead of calling every Update method as most get out really fast anyway.

Link to comment
Share on other sites

My animation is working really well, doesn't seem to be starting on the wrong frame or anything, its just an issue of the blending so it doesn't look as choppy. I still don't get what you meant about the blend. I tried setting the blend by decreasing the idle by 0.01 and increasing the walk by the same value. I also set the min/max so it would reset after it hit those values. My character just walks as normal and I really do not notice any blending. (Yes I did set the Blend parameter).

AMD Phenom II X4 B55 3.20 GHz - 8.00 GB Patriot Gamer Series RAM - AMD Radeon HD 6800 Series 1 GB GDDR5 - Windows 7 Professional 64 Bit

Link to comment
Share on other sites

My animation is working really well, doesn't seem to be starting on the wrong frame or anything, its just an issue of the blending so it doesn't look as choppy. I still don't get what you meant about the blend. I tried setting the blend by decreasing the idle by 0.01 and increasing the walk by the same value. I also set the min/max so it would reset after it hit those values. My character just walks as normal and I really do not notice any blending. (Yes I did set the Blend parameter).

I think your choppiness is due to how quickly you update the frame that needs to be play per clock cycle. You may need to update how you are determining when to play the next frame. The code I use to determine when to play the next frame in a sequence is below:

 

next_frame = (AppTime() - animationStartTime) / frameSpeed;
next_frame = fmodf(next_frame, m_fEndFrame - m_fStartFrame) + m_fStartFrame;

 

frameSpeed is set to 30.0f which is how many frames to play per second.

animationStartTime is updated by AppTime every frame

m_fStartFrame and m_fEndFrame are the start and end frames for the current sequence.

 

This setup works well for me and I use it for all my animations. Also I keep my blend to 1.0. I think you may be misunderstanding how the blend parameter works. From what I understand it determines how strong or fast the transition from one sequence to another must take place. I set mine to one because I want to go from one frame to another right away. I think that a blend parameter of less then one would work best in a slow motion scenario. This makes sense to me if you are playing the animation twice as slow as normal. In my case that would be playing the animation at 15 frames per second instead of 30 and setting the blend parameter to 0.5. Well hopefully that helps you out a bit.

Intel 2nd Generation i5 Quad Core Running at 3.30GHz. 8GB RAM, GeForce GTX 460 1024MB DDR5.

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...