KybernetikGames / animancer

Documentation for the Animancer Unity Plugin.
63 stars 8 forks source link

Issues with Snappy Transitions and Mixer Synchronization in Nested Animancer Mixers #318

Closed PixelFireXY closed 8 months ago

PixelFireXY commented 9 months ago

Hello,

I'm encountering a challenge with my character controller in Unity, specifically with the animation transitions using nested Animancer mixers. My character has multiple movement states (Walk, Jog, Run, Crouch), each with its own mixer. The problem arises with the transition between these states.

To maintain proper animation for each state, I have to set the parameters of all unused mixers to Vector3.zero. However, this leads to snappy and unnatural transitions between states. When I try to smooth out these transitions using Mathf.MoveTowards (and remove the Vector3.zero), the mixer attempts to synchronize animations with different speeds, which results in incorrect animation speeds (e.g., Walk animations move too fast, Jog is correct, Run too slow).

Additionally, when switching between states that are not adjacent (like from Run to Walk), my character starts with an idle animation, even if it's moving. This causes a brief but noticeable and unnatural pause before the correct movement animation plays.

Here's an overview of my setup:

I am seeking advice on how to achieve smooth transitions between these mixers without causing synchronization issues or unnatural resets to idle animations. Any suggestions or insights on handling these mixer transitions in Animancer would be greatly appreciated.

Full script for additional context: https://pastebin.com/u3kizeis Script using Mathf.MoveTowards: https://pastebin.com/37ka2qER

Thank you in advance for your help and expertise! Matt

KybernetikGames commented 9 months ago

Setting the parameters of the inactive mixers to zero doesn't sound right. I think it would make more sense to have one vector which you Vector2.MoveTowards and give the same value to all the child mixers every frame.

In theory, that should let the synchronization modify their speeds to keep their walk cycles aligned as the parent mixer moves between them. If it's not, there could well be a bug in the synchronization system because I haven't done much testing with nested mixers.

Another thing that might be worth trying something like movementMixer.State.FadeChildWeights((int)currMovementType, 1f / stateTransitionSpeed); whenever the movement changes. That would let it blend directly from Crouch to Walk without actually going through Run and Jog.

PixelFireXY commented 9 months ago

Hi KybernetikGames,

I've switched from using nested mixers to MixerTransition2D for my character's movement states (Walk, Jog, Run, Crouch), as per your suggestion about potential bugs with nested mixers. This change has resolved the issues with animation speed - everything is now smooth and correctly paced.

However, I'm still facing a slight problem with synchronization between different animation types during transitions. There's a noticeable lack of perfect sync, especially when changing movement types.

Also, I couldn't find the FadeChildWeights method you mentioned earlier for some reason, any tips on fine-tuning the sync between animations would be helpful. Thanks for the help

New script paste: https://pastebin.com/5v7W60s1

KybernetikGames commented 9 months ago

You can get the FadeChildWeights script from here. I forgot that it wasn't yet in the last update.

Two synchronization tips come to mind: