Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

WheelCollider - GetWorldPose

Discussion in 'Physics' started by Vancold, Jan 26, 2016.

  1. Vancold

    Vancold

    Joined:
    Oct 15, 2013
    Posts:
    7
    Hey.

    I tried to use the search function for that particular topic but i didn't get the anwser i wanted.

    SO.

    I am trying to create a simple car. Most tutorials use a WheelCollider object function called GetWorldPose for visual effects on the wheel (especially updating the wheel with the motorTorque and the RPM ect)
    So i tried. The wheels do turn and accerlate, but they are not locked on the z axis -> The wheels are parallel to the floor. I tried to create a new rotation without the z axis. (z-angle = 270)

    If i set the WheelCollider which contains my cylinder (the wheel) at a 90degree angle it will be set to 270 if i don't it is still parallel to the floor. In preview the tires look normal that way but not ingame.

    Why does it set the wheels parallel to the floor?
    The problem originates from GetWorldPose.
     
  2. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    you need to make sure your meshes have correct rotations (ie, 0,0,0) when you first drag it into the scene.
     
  3. Vancold

    Vancold

    Joined:
    Oct 15, 2013
    Posts:
    7
    Okay so the system tries to revert the angles to make it parallel. So in order to prevent this, i have to set the rotation of the mesh to a 0,0,0?

    EDIT: IF i make the car flip to the side while driving the wheels adjust PERFECTLY. Tried out what you said, didn't do to much
     
    Last edited: Jan 26, 2016
  4. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    It assumes the non changed position is 0,0,0. If your wheels have a rotation of 90,0,0 when you drag your car in the scene, your wheels are going to be rotated to 0,0,0 which means that 90 makes it look wrong.
     
  5. Vancold

    Vancold

    Joined:
    Oct 15, 2013
    Posts:
    7
    The fact that the system doesn't care about the non changed position is odd.
    I even recreated it with a tutorial in a new project. Step by step (because i thought i can't be that stupid). Same result.
    Tried to put the car into prefabs (assets). rotation values of the wheeles were 0,0,0. It stayed that way.
    Then again i was confused tried it with 0,0,90. Got corrected. It doesn't matter if i pull em in our out of the scene ect.
    GetWorldPose always creates a parallel object to the world i guess. Atleast that's what it does when i use it in different projects...
     
  6. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    Never had a problem with that tbh.

    Always worked fine unless some of the rotations were messed up
     
  7. unity_i7nkJ6nIURoi_Q

    unity_i7nkJ6nIURoi_Q

    Joined:
    Jul 12, 2020
    Posts:
    1
    Most probabaly your wheel has z axis rotation like this upload_2023-4-30_17-7-11.png

    What you have to do is make the parent object the same with wheel position rotations, but without z-axis rotation like this and drag that wheel inside that object upload_2023-4-30_17-9-35.png

    and use "wMesh.transform.parent.rotation = quat;" to get correct rotation "wCollider.GetWorldPose(out pos, out quat);"

    It works for me.