Search Unity

How to store the bone position after animation, but before it will be modified by a script?

Discussion in 'Animation' started by brightskyway, Jul 12, 2021.

  1. brightskyway

    brightskyway

    Joined:
    Nov 19, 2020
    Posts:
    8
    Hi guys.
    I`ve made a script which makes a dynamic movement for a bone chain. It adds the inertia, gravity, friction etc to an every bone. I use it on the creature tail and it works perfectly.

    Now I want to use this effect on the creature spine. But I want to use it with a characters animation which I created early. So when I move the creature in the world space, its spine keep moves with animation but slowly bend by dynamic along the direction.
    But now I stuck. I only can achieve the dynamic which overrides the spine-animation. I feel like I don`t have enough knowledges on this step.

    So what is my question?
    Inertia and friction etc depends from a current bone position. But If I will directly add the modified position to a current bone position, then in next frame I will receive a loop. And my bone will fly away.
    So I thing I need to store the fresh ONLY "after animation" bone position with no modification. Then add the dynamics to it in a LateUpdate. And in next frame again take not the resulting position but "after animation" position. Etc, again and again.

    Is it achievable?
     
  2. brightskyway

    brightskyway

    Joined:
    Nov 19, 2020
    Posts:
    8
  3. launzone

    launzone

    Joined:
    Dec 2, 2015
    Posts:
    57
    Don't know if I understand your problem completely but have you tried getting the values at OnAnimatorMove?
    Check out the unity execution order.
     
  4. brightskyway

    brightskyway

    Joined:
    Nov 19, 2020
    Posts:
    8
    launzone, yes, I`ve tried OnAnimatorMove. I store the joint pos and rot in the variable in OnAnimatorMove, then via OnDrawGizmos draw the GismoSphere with stored variable, and in a LateUpdate I assign the modified Proxy position with dynamic (which is calculated during FixedUpdate) to a bone.
    Result: in a viewport I see the Gismo sphere on the LataUpdate positon. Not on the animated.

    It looks something like this:
    Code (CSharp):
    1. private void OnAnimatorMove()
    2.     {
    3.         animPos = joints[0].position;
    4.     }
    5.     public void OnDrawGizmos()
    6.     {
    7.         if (endOfChainIsLeading)
    8.         {
    9.             Gizmos.color = Color.red;
    10.             Gizmos.DrawWireSphere(animPos, 0.4f);
    11.         }
    12.      
    13.     }
    14.  
    15.     private void LateUpdate()
    16. {
    17. // public float Weight is used for on/off the effect via inspector
    18. joints[i].position = Vector3.Lerp(joints[i].position, Proxy[i].transform.position, map(Weight, 0, 100, 0, 1));
    19. }
    20.  
     
    Last edited: Jul 13, 2021
  5. Jack_Potter

    Jack_Potter

    Unity Technologies

    Joined:
    Jun 10, 2021
    Posts:
    5
    Hi Brightskyway,

    This sounds like a good candidate for using a rigging constraint. Here you will have access to the animation stream being processed inside the animation engine.

    This talk from Unite 2019 might be helpful:


    Thanks,