Search Unity

Setting an object to Wheel Collider possition isnt centered

Discussion in 'Physics' started by xXrandomryzeXx, Oct 5, 2019.

  1. xXrandomryzeXx

    xXrandomryzeXx

    Joined:
    Jul 31, 2018
    Posts:
    13
    So I have been following a tutorial to make a car with the wheel collider, it works awesome except the part that when I try adding the Rendered wheels they don't center with the wheel collider, if you don't get what I mean here is a photo of how it should look and how it looks
    upload_2019-10-5_20-40-0.png
    and what it looks like
    upload_2019-10-5_20-40-24.png


    the code that I use to center the wheels is:
    Code (CSharp):
    1. public void UpdateWheelPos(WheelCollider col, Transform t)
    2.     {
    3.         Vector3 pos = t.position;
    4.         Quaternion rot = t.rotation;
    5.  
    6.         col.GetWorldPose(out pos, out rot);
    7.         t.position = pos;
    8.         t.rotation = rot;
    9.     }
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    Most probably those wheels have their origin located at the center of the car, not at the center of the wheel itself. That should be fixed in the 3D model itself.
     
  3. xXrandomryzeXx

    xXrandomryzeXx

    Joined:
    Jul 31, 2018
    Posts:
    13
    Yes it was like that, fixed it and i still have the same problem, tough if i look at the visual wheels (the models) their positions arent 0,0,0 or something like 7,4,9 etc.
     
  4. xXrandomryzeXx

    xXrandomryzeXx

    Joined:
    Jul 31, 2018
    Posts:
    13
    Oh and also they rotate around the center of the wheel collider(I mean of the collision wheel) but their distance is fixed and I cannot change it(that means that if I try moving them manually they return back to their position). I will try looking at the variables and maybe change them. Though it might be just hardcoded :/