Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Stutter with nested kinematic rigidbodies

Discussion in 'Physics' started by dgoyette, Feb 10, 2019.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,193
    I'm experiencing some stuttering when moving a kinematic rigidbody, where other non-kinematic rigidbodies on the object jitter while the object is moving.

    I have an elevator platform composed of two pieces: The "leg", which moves up and down, and the "platform", which can rotate. Each of these objects has a collider and a kinematic rigidbody, such that the "platform" is a child of the "leg". Here the "leg" is circled in blue, and the "platform" is in red:

    upload_2019-2-10_13-20-31.png

    The issue is that if I make the "leg" go downward, and I stand on the platform (I'm a non-kinematic rigidbody), I keep stuttering on the way down, as if I'm falling tiny amounts every couple of frames. I'm moving the leg via Rigidbody.MovePosition. If this were all a single Rigidbody, then it moves smoothly. But because the platform is a separate nested kinematic rigidbody, I get this behavior.

    Is there a way to get nested/child kinematic rigidbodies to move smoothly as the parent moves? I need a kinematic rigidbody on the platform because with out, collision forces aren't registered for that platform as it moves.
     
    JoJa15 likes this.
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,193
    To put it another way, to make sure the problem is clear, here's a simplified version:

    upload_2019-2-10_16-38-56.png

    The lower block has a collider and Kinematic Rigidbody, as does the upper block. The upper block is a child of the lower block. I'm moving the lower block up and down with MovePosition on the lower rigidbody.

    If I disable the upper block, then the player rides up and down smoothly while standing on the lower block. But if I enable the upper block, the player doesn't "stick" to the block when it moves down. Instead, it's like they stand in mid air for a fraction of a second, and then fall to land on the block, repeatedly, until the block gets to the bottom of its motion.

    I've tried connecting the two kinematic rigidbodies with a fixed joint, but that doesn't change the behavior. I've tried removing the rigidbody on the upper block, but then the upper block's no longer exerts physics forces on objects in the scene. (Or, at least, ComputePenetration no longer gives me results.)
     
  3. JesterGameCraft

    JesterGameCraft

    Joined:
    Feb 26, 2013
    Posts:
    452
    You should be only using one rigidbody on the parent, from doc: When creating a compound collider like this, there should only be one Rigidbody component, placed on the root object in the hierarchy.

    When you remove rigidbody from the upper block does the player "ride" down smoothly?
     
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,193
    Thanks. Having a single rigidbody resolves the issue. The reason I had two rigidbodies is because it seemed that certain forces weren't being applied when the child object rotated. But I think I have that all sorted.

    So thanks for convincing me to go back and take another stab at this. The one-rigidbody approach is definitely the way to go.
     
  5. JesterGameCraft

    JesterGameCraft

    Joined:
    Feb 26, 2013
    Posts:
    452
    Np. Glad it worked.