Jump to content
  • Advertisement
Sign in to follow this  
Medo Mex

Blending Two Animations

This topic is 1708 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Lets say I have 4 different animation presets inside "character.x":

- Idle

- Walking

- Running

- Reloading weapon

 

I can play any of them, switch between idle to walking smoothly, but

 

How do I play both animations "running and reloading weapon" at the same time?

 

I have been looking for any code sample to accomplish that using D3D9 but I didn't find any.

 

I'm using D3D9 Animation Controller ID3DXAnimationController.

Share this post


Link to post
Share on other sites
Advertisement

I'm able to do animation blending by assigning the two animations into two animation tracks.

 

But now I have another problem, how do I make the transition smooth? I have done it with single animation track, but when I have two animation tracks playing at the same time (animation blending) I don't know how to make the transition smooth between the old animation and the new one.

Share this post


Link to post
Share on other sites

use ::SetTrackEnable() to enable the tracks you want to blend.

use ::SetTrackWeight() for each track, to transition between two enabled tracks.

Edited by Tispe

Share this post


Link to post
Share on other sites

From a technical point of view, the 4 animations enumerated in the OP may require up to 3 different mechanisms:

 

1. Idle <-> Walking often requires one or perhaps 2 modeled animation (i.e. no blending at all) for transitions to look realistic / aesthetic.

 

2. Walking <-> Running can be done with blending. However, both animations are cyclic, and hence blending requires the permanent alignment of the animation phases (i.e. relative acceleration of walking and deceleration of running) during the weighting being truly between 0 and 1.

 

3. Reloading Weapon is usually implemented as override to a part of the other animations (i.e. it does influence the arms but it doesn't influence the legs); this is often called "animation layering" instead of animation blending.

 

Unfortunately, I'm not familiar with D3D's animation controlling, but perhaps the above hints help in finding suitable solutions.

Share this post


Link to post
Share on other sites

@Tispe: That works well ONLY if I'm playing one animation in the animation track, usually I set the old animation on one track and the new one in the other track and I get smooth transition, but now I'm trying to play 2 animations on the track at the same time.

 

The following make the transition smooth if I'm switching between one animation to another:

animController->KeyTrackEnable(m_currentTrack, false, m_currentTime + transitionTime);
animController->KeyTrackWeight(m_currentTrack, 0.0f, m_currentTime, transitionTime, D3DXTRANSITION_LINEAR);
animController->SetTrackEnable(newTrack, true);
animController->KeyTrackWeight(newTrack, 1.0f, m_currentTime, transitionTime, D3DXTRANSITION_LINEAR);
 
In my case I have to apply 2 newTrack instead of one, but I couldn't make it smooth like in the above code.
 
I tried something similar to the above code, but it reset both animations (while I only want to change one animation on track at once, not both)
Edited by Medo3337

Share this post


Link to post
Share on other sites

perhaps becuse when you add the new track, animController->SetTrackEnable(newTrack, true);  the current weight is default to 1.0f. Then you try to transition from 1.0f to 1.0f. Try setting the weight of the new track to 0.0f first.

Edited by Tispe

Share this post


Link to post
Share on other sites

@Tispe: Let me explain to you better:

 

Available Animation presets:

- Walk

- Run

- Reload

 

Here is example:

character->walk();
delay(5000); // Delay for 5 seconds
character->reload();

What do I expect from the above code?

The character starting walking and after 5 seconds he will reload his weapon WHILE still walking.

 

What happens instead?

The character start walking, but when he reload, the "walking" animation RESET

 

What should happen?

When the character reload his weapon, the animation transition should only affect his arms and not his legs, the walking sequence should not get affected

 

I can only resolve this problem when I don't have animation smooth transition by only changing the intended animation track while leaving the other as it is, but how do I fix it while I have smooth transition?

Edited by Medo3337

Share this post


Link to post
Share on other sites

I'm not quite sure what the problem is. If your reload animation has animation keys for your legs then that track will affect them.

reload(){
animController->SetTrackWeight(m_ReloadTrack, 0.0f);		//init weight to 0
animController->SetTrackEnable(m_ReloadTrack, true);
animController->KeyTrackWeight(m_ReloadTrack, 1.0f, m_currentTime, transitionTime, D3DXTRANSITION_LINEAR);	//Start the animation with linear transition blending


//I don't know if you can stack these events. Give it a try anyway. If not this part must be run when you want to turn off the reload animation
animController->KeyTrackWeight(m_ReloadTrack, 0.0f, m_currentTime+transitionTime+AnimationLength, transitionTime, D3DXTRANSITION_LINEAR);
animController->KeyTrackEnable(m_ReloadTrack, false, m_currentTime+2*transitionTime+AnimationLength);
}

Share this post


Link to post
Share on other sites

@Tispe: No, the reload animation is only for reloading, run animation is only running.

 

I want to play both animations run and reload (at the same time)

 

He is my current code to play 2 animations at the same time (and it's working):

animController->UnkeyAllTrackEvents(m_currentTrack);
animController->UnkeyAllTrackEvents(newTrack);

// Get animations
animController->SetTrackAnimationSet(0, walkAnimSet);
animController->SetTrackAnimationSet(1, reloadAnimSet);

// Assign "walk" animation to track 0
animController->SetTrackEnable(0, true);
animController->KeyTrackWeight(0, 1.0f, m_currentTime, transitionTime, D3DXTRANSITION_LINEAR);
animController->SetTrackSpeed(0, 1.0f);

// Assign "reload" animation to track 1
animController->SetTrackEnable(1, true);
animController->KeyTrackWeight(1, 1.0f, m_currentTime, transitionTime, D3DXTRANSITION_LINEAR);
animController->SetTrackSpeed(1, 1.0f);

The only problem is that the animation transition is not smooth, how do I make the transition smooth?

Edited by Medo3337

Share this post


Link to post
Share on other sites

If you want to walk while reloading then you don't transition between any tracks at all, you simply enable the reload animation ontop of the walk animation.

 

If you want to smoothly enable the reload animation then you gradually increase its weight from 0.0f to 1.0f, all while the walk track is weighted 1.0f.

 

If your walking animation makes your arms swing back and forth then the reload animation will "fight" with the walking animation for control of the arms. Therefore it is normal that the reload animation do not have animation keys for lower body bones, and walk animation do not have animation keys for upper body bones. A walk animation will then have to be composed of lower body + upper body, two tracks just to walk!

 

Then you gradually swap out the "walk-upper" animation with the reload animation, which only affects the upper body.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!