KybernetikGames / animancer

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

Adding AnimationCurve to control collider size during jump #52

Closed mutp closed 4 years ago

mutp commented 4 years ago

I'm looking to add a curve to my animation model so that I can dynamically adjust the collider height and position during the animation.

Using Mechanim, it is done as seen in the following video - https://www.youtube.com/watch?v=Xx21y9eJq1U&feature=youtu.be&t=2161

To do something similar using Animancer, I'm using the Uneven ground example. I've used AnimatedProperty which is initialized with the same name as the Property Name in the model file. image

In code, I'm doing this - colliderHeight = new AnimatedProperty(Runner.Animancer, AnimatedProperty.Type.Float, "ColliderHeight");

However, when I play this animation, and print out the value of colliderHeight, I don't get the same values as defined in the curve. Is this the right way to do it?

mutp commented 4 years ago

Also, I've used the Exposed Curve way of doing it, and AnimatedProperty way, I get different values from each initially and then they converge? Not sure what's going on. (The values from Exposed Curve are correct).

image

KybernetikGames commented 4 years ago

The value the Playables API gives an AnimatedProperty is blended according to the animation weight, so animations without that curve would be treated as 0 which would cause it to start smaller than expected while your jump animation is fading in. Mecanim parameters work the same way.

To work around that, you could instead use the curve as an offset (or multiplier) for the default height so everything at 0 leaves it and the curve for your jump animation starts at 0, goes down for a bit, then back up to 0.

mutp commented 4 years ago

After updating to v5.0, I changed all AnimatedProperty references to AnimatedFloat but I'm getting this warning and the animation doesn't play. image

KybernetikGames commented 4 years ago

The way Unity reports which properties can be used unfortunately doesn't detect AnimatedFloats (and wouldn't have detected AnimatedProperty if I had implemented that warning system back then either). So that won't be the source of your problem.

Take a look at the Debugging page and see if you can narrow down the issue.

Does the animation show up in the AnimancerComponent Inspector?

mutp commented 4 years ago

Yup, it shows up but with the same warning. It doesn't play the animation, just the first frame. image

I will also try to debug this further.

EDIT: it works if I just use an Animator.

KybernetikGames commented 4 years ago

Could be something wrong with the way the mixer is being initialised.

What does your code look like?

Have you checked the state details to make sure the speed isn't set to 0 or something like that?

mutp commented 4 years ago
private void OnEnable()
{
    print("[LocomotionState] OnEnable");

    var state = Runner.Animancer.Play(RunAnimations, Runner.locomotionFadeInTime, FadeMode.FixedDuration);
    state.NormalizedTime = Runner.locomotionNormalizedTime;

    print("[LocomotionState] NormalizedTime: " + Runner.locomotionNormalizedTime + ", FadeInTime: " + Runner.locomotionFadeInTime);

    IsRunning = true;
}

State has normal speed image

mutp commented 4 years ago

This issue doesn't happen for my other animations which use ClipState.Transition

KybernetikGames commented 4 years ago

I just noticed you said you're using v5.0, but v5.1 is the latest and has a bug fix in mixers that might affect this.

If not, could you try to narrow down the problem and send me a minimal reproduction project so I can take a look at it?

mutp commented 4 years ago

I've updated to v5.1 and the issue persists. Attaching a sample project. The script on "Runner" can switch between the LinearMixerState and a ClipState for the same animation, using a bool. You can turn it on or off to see the issue.

KybernetikGames commented 4 years ago

Looks like a bug in the Extrapolate Speed system added in v5.0. I've posted a Separate Issue explaining how to fix it.

Also, I've removed your attachment. Please don't post the source code of Animancer publicly. Reproduction projects should either be sent to me via email or you can just remove Animancer from the project before uploading and I'll add it back in on my end.

mutp commented 4 years ago

Ah, right. Sorry about that.