Search Unity

Question attach a kinematic child rigidbody to a parent

Discussion in 'Physics' started by meiru, May 3, 2023.

  1. meiru

    meiru

    Joined:
    Aug 11, 2017
    Posts:
    19
    Can I attach a kinematic rigidbody to an other rigidbody (non-kinematic) by setting it as its parent? (and will it follow the movements of its parent?)
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    Yes but it'd take no time to quickly check it rather than wait on a forum post. :)
     
  3. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,445
    You can. It will have no effect. Basically the isKinematic flag disables the Rigidbody (instead of .enabled on most other components). The physics system completely ignores it. (And movement is thus based on just transform parent matrices.)

    I'd have to run a test but I think even collision messages skip them if there's another Rigidbody higher in the chain. Maybe MelvMay would know off-hand about that one. Or as he says, just try.
     
  4. meiru

    meiru

    Joined:
    Aug 11, 2017
    Posts:
    19
    I tried it and it worked, but many told me, that this is not a good idea and would not work or if it works, it is just because of luck or a bug or whatever... that's why I decided to ask here. :)
     
    MelvMay likes this.
  5. meiru

    meiru

    Joined:
    Aug 11, 2017
    Posts:
    19
    Sounds great. That is exactly what I want.
     
    MelvMay likes this.
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    To be clear though, Kinematic is just another body-type (Dynamic, Kinematic and Static) where it doesn't have a collision response and isn't affected by external forces which might sound like it's ignored by the physics system but that's not true because there's more going on there than those two things.

    Confusion here is caused by devs setting a body to be kinematic to stop it interacting this way but that isn't it being disabled in any way. It changes its behaviour. :)

    A Kinematic body still has colliders which interact with other colliders and can be queried by the physics system. This isn't the equivalent of disabling a component or GameObject.

    There's also subtle differences for a Kinematic body in 2D vs 3D physics such as 3D doesn't allow you to set a velocity of a Kinematic body, the 2D physics does.

    "Kinematic" should be thought of as "User Controlled".
     
    meiru likes this.
  7. meiru

    meiru

    Joined:
    Aug 11, 2017
    Posts:
    19
    Thank you for the detailed explanation. It helps me a lot to know all this.
     
    MelvMay likes this.