Search Unity

Is there a way to modify root motion transition interpolation via script?

Discussion in 'Scripting' started by Tiernan98, Dec 13, 2020.

  1. Tiernan98

    Tiernan98

    Joined:
    Jul 11, 2017
    Posts:
    42
    Hey,

    So I have some root motion-based animations for a 3D character. Currently, I take the Animator deltaPosition and send it to a character controller move function so that all collision, etc are properly recognised and it is easy to switch between root motion and script velocity.

    There are some animations as I posted here: https://forum.unity.com/threads/what-causes-this-jerking-in-transition.1015630/ that do not behave as I would like during transitions. Maybe it is just a lack of knowledge on my part about animation, but it jerks even though there is only forward root motion on both clips.

    One idea I had was to implement the transition interpolation myself, by taking the delta positions at each clip at the time in the transition and doing a sort of LERP depending on far into the transition we are. I believe this would give me the desired behaviour, but I am not sure how at runtime I can access the delta position values for each clip? Animator.deltaPosition would be equal to whatever the transition has calculated.

    Appreciate any help, thanks!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Looking at your other post, the problem might be more the center of mass of each animation: it looks like the character is leaning forward during run and then leaning back as he slows, which would make sense. I guess that when you say it looks good transitioning from certain parts of the walk animation but not others, that's just because we're expecting at what phase in a running cycle such a transition would look good.

    Have you tried just waiting until a certain point in the run animation is reached and then transitioning? It might be better than you think it would be. In other words, having the run persist a moment longer than necessary might be less jarring than what you have in the gif in that other post.
     
  3. Tiernan98

    Tiernan98

    Joined:
    Jul 11, 2017
    Posts:
    42
    What you say makes sense if that is the explanation. Thanks for the response! :)

    I have tried that and I think probably because the run loop is not that short (its more a jog speed than a run), it doesn't feel responsive to wait. The character runs too long unless you stop at the right time. I've seen in AAA games of a similar style the run will stop as soon as you let go of the control with only two stop animations. What is different about how those animations are being processed or made?
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Hard to say. Could be they even hand insert another fore-aft offsetting animation to smooth it out? I'm thinking perhaps just a temporary "ease forward then back" type thing to smooth what you're seeing.

    It's also possible they have an actual set of specific transition animations to take you from various parts of the run cycle back to idle, rather than just trying to blend it. Really depends on the game and how crazy their animators went!
     
  5. Tiernan98

    Tiernan98

    Joined:
    Jul 11, 2017
    Posts:
    42
    I think I've figured it out with your help.

    You led me in the right direction when you started talking about the character's centre of mass. It made me think it was something to do with different processing on Generic and Humanoid avatars. I switched from Humanoid to Generic on my model and animations. It behaves exactly how I want. Even if I put the completely wrong stop animation at the worst possible time the local rotations of the bones look weird but the character smoothly comes to a halt.

    Now I have to deal with the fact that I can't mirror Generic animations in Unity. I guess I will just have to do that in Maya. Also makes swapping out models harder, but should be able to if I skin the original skeleton onto them. First time working with Generic animations funny enough lol.
     
    Kurt-Dekker likes this.