Search Unity

Control Animation at Runtime

Discussion in 'Animation' started by andrematui, Apr 17, 2019.

  1. andrematui

    andrematui

    Joined:
    Jul 8, 2015
    Posts:
    5
    Hello everyone,

    I am trying find a way to add more control over animations at runtime, like controling root motion translation, rotation etc.

    One example of something I want to do is use the same "pounce" animation to make the character reach points with different distances and heights.
    To achieve that I tried messing around with additive layers, but found out that I can only apply root motion to override.

    I looked into a GDC talk about how they did the animations for the new DOOM and it's pretty much what I want to make work, but I'm struggling to find the way to do it inside unity.


    Does anyone have any insight?
    Thank you for your time!
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    It sounds like you might be interested in my Animancer plugin (link in my signature) which gives you much more control over everything at runtime.

    For root motion correction I'd probably use an Animation Event to mark the landing time. Then at runtime you can just feed the current time and event time into the formula they explained and apply the resulting delta as additional force in FixedUpdate. Extending that into a "window" with a start and end time would just mean adding a start event as well.

    Focus Tracking would just be something to script in LateUpdate. Though if performance is critical, Animation Jobs would likely be better.

    Blend Trees already do Foot Phase Tracking so most of the time I just use an AnimatorControllerState to play a controller that contains only the locomotion Blend Tree and keep the rest of my AnimationClips separate. If you wanted to implement it yourself you could use AnimationMixers which are basically Blend Trees without the Foot Phase Tracking, but you have full scripting access to the states and their blending at runtime. So you would analyse the foot phases in the editor and store the details in a ScriptableObject, then use that data (and whatever other inputs you want your system to consider) to manage the mixer at runtime.
     
    unity_iogames likes this.
  3. andrematui

    andrematui

    Joined:
    Jul 8, 2015
    Posts:
    5
    Thank you for replying so quickly!

    Your plugin is exactly what I was looking for. Gonna dig right in!
     
  4. andrematui

    andrematui

    Joined:
    Jul 8, 2015
    Posts:
    5
    Is there a way to do this while preserving the root motion movement?
    I'd like to keep using the animation's original movement and add the correction to that, so far I've only come up with ways to override the original movement.
     
  5. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    If you have root motion enabled, you should be able to add whatever you want on top of the movement it applies.