Search Unity

Wheel Joint 2D

Discussion in '2D' started by langem, Jul 13, 2014.

  1. langem

    langem

    Joined:
    Mar 18, 2013
    Posts:
    73
    Hi everybody,

    I'm trying to use the new Wheel Joint 2D (with 4.5.2) and I just can't figure out how to use it (nothing in the forum/answers/documentation as well). So here's my problem. The wheels (gameobject + wheel joint + circle collider + rigidbody 2d) are properly attached to the car body ( rigidbody 2D + polygon collider). Hitting play results in the wheels attached nicely and the suspension is working well.... BUT if I apply motor torque to the wheels not only the wheels start to rotate, but the direction of the suspension also. The result is a really wobbly movement...

    I kind of fixed it by adding this to the wheels:
    Code (CSharp):
    1.     void Update () {
    2.     JointSuspension2D js = wj.suspension;
    3.     js.angle = 90-this.transform.localEulerAngles.z;
    4.     wj.suspension = js;
    5.     }
    ... but that can't be the ultimate solution, or? What am I doing wrong?

    car.JPG

    Thanks and best regards,
    Matthias
     
  2. danzhor

    danzhor

    Joined:
    Sep 7, 2013
    Posts:
    8
    I just came across other thread, where it was explained that the wheeljoint2d should be attached to the base car rigidbody. Not to the wheels. I was searching for it too, didn't test yet, but I guess that is how it should be done.

    so attach two wheeljoint2d to your box and connect each one with corresponding wheel.

    edit: now I see that this thread is a bit older so maybe a little bit late to the party... but I hope it will help at least somebody who will find this thread in future.