Search Unity

Question Animating the colliders of a kinematic rigidbody

Discussion in 'Physics' started by lgarczyn, Nov 13, 2023.

  1. lgarczyn

    lgarczyn

    Joined:
    Nov 23, 2014
    Posts:
    68
    I have a large ship, composed of about a hundred concave colliders. It's a single kinematic rigidbody, as it needs to move and be interpolated.

    During some animations sequences, all the parts of the ship move "outward", according to pretty simple math.

    Currently, all the colliders of the rigidbody are moved by setting the local position of each collider every frame.

    This can cause some lag (70fps => 40fps), even if the new localPosition is the same as the old one.

    From what I understand, the physics engine has to rebuild the entire rigidbody every frame, and no interpolation may be applied for the movement of the individual parts.

    I've tried:

    1. Making the moving parts non-kinematic rigidbodies held with fixedjoints. This is much worse for performance.
    2. Making the parts kinematic rigidbodies with constraints, but MovePosition doesn't appear to work with a constrained kinematic rigidbody.
    3. Making the parts kinematic rigidbodies with no constraints, but I have to recalculate the supposed local position every frame, even when not animating. No performance gain.
    4. Using ArticulationBodies. Does. Not. Work.

    So yeah, is there any documentation on parenting kinematic rigidbodies, animating kinematic colliders, or any other solution?