Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Moving rigidbody child colliders

Discussion in 'Physics' started by tspk91, Jan 2, 2018.

  1. tspk91

    tspk91

    Joined:
    Nov 19, 2014
    Posts:
    130
    Does moving child colliders in a compound collider incur in a performance penalty, even if the center of mass is manually set?

    -Parent with non-kinematic rigidbody and collider
    -Child Collider
    -Child Collider (moved by code locally)

    I want to avoid using joints because of their complexity and fickleness, as I just want to move the child in a very specific way. And I need the parent rigidbody to react to collisions against the moving child collider.
     
  2. KeithKong

    KeithKong

    Joined:
    May 31, 2015
    Posts:
    73
    I've been after a similar functionality trying to get the equivalent of heavy friction joints where external collisions don't affect the relative trajectory of joint pieces (but does affect the trajectory of the body as a whole). Unfortunately this is not currently possible. These are the two closest solutions and their pitfalls:

    1) Use kinematic rigidbodies for child joints.
    Pitfall: Collisions with child joints won't change the main body physically.

    2) Move child colliders with code as you suggest.
    Pitfall: The local movement does not register with the physics engine so inaccurate physical results occur where objects penetrate more than they should or exit out unrealistically. Small/slow rotations (or somehow stopping movement when a collision is close to happening) are mediocre workarounds. Really only works for situations where something rarely moves and is unlikely to collide during that movement.

    For performance, I've been meaning to test the cost of this but haven't gotten around to it. I do believe there will be some collision data calculations whether or not you set the center of mass but that should at least stop the center of mass calculation, saving you some. Any performance data you end up finding would be helpful ;)