Search Unity

Feature Request Interpolation for Articulation Bodies

Discussion in 'Physics' started by Qleenie, May 22, 2023.

  1. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    868
    Hey,

    I really like working with Articulation Bodies, they have some big advantages in terms of stability vs Rigidbody / / Joints.
    However, having no interpolation means the usability for visual pleasing animations is very hard. We have very complicated code parts just to compensate for the missing interpolation feature. Would be really helpful to have same interpolation toggle as we have on Rigidbodies.
     
    zezba9000 likes this.
  2. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    992
    Is this missing? Or are we just missing something here?
     
  3. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    868
    It’s still not existing. However, in newer versions of Unity you can execute Physics in Update instead of FixedUpdate, have not tried it though. But in theory this should mitigate the issue.
     
  4. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    992
    Updating the physics engine in Update with a variable deltaTime is a horrible idea and would cause huge stability issues.
    Manually adding your own interpolation would be much better. For my needs things seem to be running smooth so looks like I'm find here.

    You can do prediction by continuing to offset positions and rotations in Update based on vel * deltaTime.
    Or you could turn up the physics iteration count to 100 instead of 50 to help
     
  5. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    868
    Whether it runs smooth depends on your fixed timestep, not on the number of iterations. If you set fixed timestep very low, it will also appear very smooth, as Physics are updated more often.
     
  6. alexanderperrin

    alexanderperrin

    Joined:
    Dec 15, 2016
    Posts:
    67
    Also super suprised to see that articulation bodies don't support interpolation. Would love to have this feature added too.
     
    Qleenie likes this.
  7. codebiscuits

    codebiscuits

    Joined:
    Jun 16, 2020
    Posts:
    92
    alexanderperrin likes this.
  8. alexanderperrin

    alexanderperrin

    Joined:
    Dec 15, 2016
    Posts:
    67
    Oh amazing, thanks for sharing. That looks really clean.

    My super hacky but weirdly stable and elegant workaround was as follows:

    Code (CSharp):
    1. /// <summary>
    2. /// Component for aligning an object with an articulation body whilst preserving interpolation.
    3. /// </summary>
    4. public class ArticulationBodyInterpolationGhost : MonoBehaviour
    5. {
    6.     [SerializeField] private ArticulationBody m_ArticulationBody;
    7.  
    8.     private Rigidbody m_Rigidbody;
    9.  
    10.     private Transform m_Transform;
    11.  
    12.     private void Awake()
    13.     {
    14.         m_Transform = m_ArticulationBody.transform;
    15.         m_Rigidbody = gameObject.AddComponent<Rigidbody>();
    16.         m_Rigidbody.interpolation = RigidbodyInterpolation.Interpolate;
    17.         m_Rigidbody.isKinematic = true;
    18.         m_Rigidbody.hideFlags = HideFlags.NotEditable;
    19.     }
    20.  
    21.     private void FixedUpdate()
    22.     {
    23.         m_Rigidbody.MovePosition(m_Transform.position);
    24.         m_Rigidbody.MoveRotation(m_Transform.rotation);
    25.     }
    26. }
    This component was placed on a child of the articulation body which contained all the renderer components. The 'ghost' rigidbody then follows the articulation body around and does the interpolation for me.

    Your solution sounds much cleaner though. Will give it a go!
     
    codebiscuits likes this.
  9. codebiscuits

    codebiscuits

    Joined:
    Jun 16, 2020
    Posts:
    92
    Ah, it's Augustinas-Simkus's solution, not mine:) &, probably a better solution!
    With mine, I was caching the position etc in the previous and current FixedUpdate and lerping between the cached positions in Update. It looks like I took some shortcuts in mine (I think physics was controlling the parent of the visual mesh, and so I was lerping the visual mesh between reads of the parent position), hopefully Augustinas-Simkus's is awesome for everything:) If you have problems with it I can have a look too, it's something I need to fix at some point anyway.
     
    Last edited: Feb 22, 2024
    alexanderperrin likes this.