Avindr / MxM-IssueTracking

7 stars 0 forks source link

KCC Integration results in faulty root motion when playing an event animation #41

Closed mindvolution closed 4 years ago

mindvolution commented 4 years ago

Playing an event animation with Kinematic Character Controller has faulty outcome with root motion position and rotation

When playing without KCC the faulty behaviour is not present

Left: with KCC - Right: without KCC compare

Press 'C' to perform the crawl animation

Access to project: https://github.com/mindvolution/MxMKCC

Avindr commented 4 years ago

Sorry, it's taken me a while to get around to this one and unfortunately the repo invitation has expired. Could you send it through again? Cheers.

Avindr commented 4 years ago

Which version of Unity are you using? Also which scene is it?

When I opened the project I got a bunch of serialization errors which are probably due to opening in an older version than it was created.

Avindr commented 4 years ago

I think I may have found your problem. However, I'm not able to confirm as all the animations are corrupt for some reason when I open the example project.

I did note that on your character you have the "Animator Update Mode" set to 'Normal'. Since Kinematic Character Controller updates in the fixed update loop, the Animator should be set to "Animate Physics".

Try this first and if it still has the issue let me know and I'll dig further.

mindvolution commented 4 years ago

Unity Version 2019.4.0f1 Scene: MotionMatchingTest

Did you download the .zip file from github or did you clone the project? There are LFS files which are not in the zip when downloading from the github page. I just deleted the project locally and cloned it but got no corrupt animations only some import warnings. Also got some stuttering now when running, but I think you can ignore that, it's not the case in our original project.

Tried setting the Animator Update mode to "Animate Physics" but unfortunately it didn't help

Avindr commented 4 years ago

Ok Cheers. I'll try that

Avindr commented 4 years ago

A bug was found in the KCC integration following re-production. Very small movements were being shaved off root motion to avoid erratic behaviour. KCC appears to be very sensitive to this due to the accumulation of root motion over multiple frames.

The clamp value for root motion has been exposed to the inspector and can be modified to suite the users needs including at runtime (default 0.0000275 comparing to sqr magnitude of velocity).

I found it difficult to find a good clamp cut-off because there was a very small threshold between erratic behaviour and cutting off small motions. This is inherent with how KCC works as a fixed update (accumulated motion) character controller. I deemed the best solution and allow the user to set it themselves and even change it at runtime if necessary to provide a workaround of edge cases.

Additional Bug: An additional bug was found and fixed during this investigation. Angular Error warping was running during the crawl event which should not occur. I modified the check to see if AngularError warping is possible so that it cannot occur during an event.

Additional Considerations for using KCC in this setting:

The above mentioned bug fixes will be available with MxM v2.2.5