Search Unity

Attach a trailer to a truck

Discussion in 'Physics' started by cruising, Aug 30, 2017.

  1. cruising

    cruising

    Joined:
    Nov 22, 2013
    Posts:
    329
    Hello!

    Im trying to attach a trailer to a truck.

    1: I add a rigidbody to the trailer
    2 I add a collider to the trailer
    3: I adding 4 wheelcolliders where the trailers wheels are.
    When i then press play and the wheelcolliders touch the terrain, the trailer goes crazy flying and spinning around in the air.
    Why?

    Then i just adding a hinge joint and the truck and trailer flies away like crazy.
    The acually truck works fine without the trailer.

    So what am i doing wrong? i just want the trailer to follow the truck like it should do and nothing else.
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,508
    I'd try configuring the trailer with 4 wheels, but one wheel at each corner (like in a regular car). Once that setup works, try moving the wheels to the correct positions.

    If the problem persists the issue might be related with the fact that Unity calculates the wheel's sprung masses based on the position of the center of mass, but assuming that the center of mass is located within the boundaries of the wheels in the XZ plane. The case of the trailer, where the center of mass is outside the boundaries of the wheels, is not directly supported and the result is undefined.
     
  3. cruising

    cruising

    Joined:
    Nov 22, 2013
    Posts:
    329
    Hello Edy.

    I did what you said and it sort of works. the problem seams to be the collider.
    If i start the game with the collider active, the trailer (join point) keep falling down on the truck and bouncing so the truck cant drive away, if i then (at run time) uncheck the collider, everything works fine.

    If i then start the game with the collider unchecked, then the wheelcolliders start to go crazy jumping.
     
  4. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,508
    That's because the inertia tensor is computed out of the colliders when the vehicle is enabled. If there are no colliders available at that time then the inertia tensor stays at the default value (1,1,1). WheelColliders rely on the inertia tensor for some -incorrect, IMHO- reason, thus causing the effect you observe when the tensor is not initialized.

    You may try setting the inertia tensor yourself. Read Rigidbody.inertiaTensor after initializing the vehicle with the collider active. Note down the value, then use it for initializing the inertia tensor when initializing the vehicle with the collider disabled.
     
    Last edited: Aug 31, 2017
  5. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,508
    Maybe "Enable Collision" is checked in the joint? Try disabling it.