Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Adding child rigidbodies to a car jerks the car around - best rb practices?

Discussion in 'Physics' started by Cooo_oooper, Dec 30, 2023.

  1. Cooo_oooper

    Cooo_oooper

    Joined:
    Apr 20, 2023
    Posts:
    37
    I have a basic car set up in my scene with all that there is to it. Rigidbody, Collider, WheelColliders.
    Now I add some item to this car as a child that has a Rigidbody set to be Kinematic and not use gravity and a Boxcollider.
    However my car doesn't drive normally when I do this this. When I add the child the car jerks around and drives slowly and steers badly. There are no collisions going on between the car and the item I added.

    Is there any way to add this child rigidbody without the car behaving weirdly?
    Added a video to explain better:

    From what I could gather this is because I am adding the children with their box colliders to the rigidbody of the parent, which recalculates the center of mass and this messes up the physics even though I set the children to be non kinematic.
     
    Last edited: Dec 30, 2023
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,531
    In that case, you may disable the automatic recalculation by just assigning the value of the center of mass manually. Same for the inertia tensor. If you want to preserve the initial values calculated automatically, then simply assign them to themselves once the car is initialized:
    Code (CSharp):
    1. rb.centerOfMass = rb.centerOfMass;
    2. rb.inertiaTensor = rb.inertiaTensor;
    3. rb.inertiaTensorRotation = rb.inertiaTensorRotation;
     
    Cooo_oooper likes this.
  3. Cooo_oooper

    Cooo_oooper

    Joined:
    Apr 20, 2023
    Posts:
    37
    Thank you so much Edy! This finally fixed it for me after a lot of headaches
     
    Edy likes this.