KybernetikGames / animancer

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

Mask not stopping animator from controlling bones. #315

Closed hyper-active closed 9 months ago

hyper-active commented 9 months ago

I'm trying to setup a system so the NPCs head can look around free of the animation that's currently playing.

Using a mask to only animate the body to test, so that I can freely move the head, doesn't seem to work.

I then did a test and masked out all the bones, then ran the animation. As expected, the animation plays in the Animancer inspector but the NPC doesn't move. Because I masked out all the bones. But... I can't move any of the bones manually either, even in the Scene window, or via transform in script.

So, I'm masking and that's working. But there's something else that's blocking all the bones in place, no matter what mask/layer I use. Any help here to understand what's going on would be appreciated, and/or a different solution to release bones occassionally for me to adjust manually (like if I wanted the NPCs head to look at the player while they do other stuff).

I see that in layers I can do several layers blending in different animations. But that's not really what I'm trying to do here. To clarify, for example I have an idle animation with all bones being used. I want to be able to override the head bone so I can rotate the NPC head to face the player when I like. It's not an animation, I'll just rotate the head in script with LookAt or something similar.

Thanks!

KybernetikGames commented 9 months ago

If your character Rig is Humanoid, then masking won't affect which bones it controls because it always controls the whole Humanoid Rig.

I'd generally apply a Look At system in LateUpdate so it gets re-applied every frame after the animation update and doesn't necessarily care whether those bones are animated or not.

hyper-active commented 9 months ago

I see. Thanks for the response, I did do this initially but the issue is I haven't found a way to smooth that movement. Overriding the head rotation in LateUpdate is easy and works, but smoothing that movement so the NPCs turns their head towards/away from the player when needed just doesn't work, there's a conflict of movement here with the animation.

I assumed the layers would solve this. If not, is there a way in Animancer to handle this?

hyper-active commented 9 months ago

Also my rig isn't humanoid, I was masking the transforms.

KybernetikGames commented 9 months ago

Looks like even with Generic rigs, masks only affect the blending between animations, but don't affect which bones are being controlled overall.

If you want a soft turn, you can just use Quaternion.Slerp. Each frame the animation system will control the bone, then in LateUpdate you slerp it from its animated rotation towards your look rotation using a t value which you increase over time (up to 1) while you have a look target and decrease while you don't.

hyper-active commented 9 months ago

That's clever thanks, works like a charm! Appreciate your time.