Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to tilt wheels?

Discussion in 'Physics' started by unity_ECD095A803223483EF8A, Aug 22, 2023.

  1. unity_ECD095A803223483EF8A

    unity_ECD095A803223483EF8A

    Joined:
    Apr 20, 2023
    Posts:
    11
    Hi everyone! The question is - how to tilt the wheels like on the picture?
    - - -
    tilt_wc.jpg
    - - -
    In game mode, collider rotation values return to zero. Apparently the wheel collider does not support rotation. Therefore, the wheel mesh needs to be tilted. Can someone tell me how to do this?
     
  2. tjmaul

    tjmaul

    Joined:
    Aug 29, 2018
    Posts:
    464
    In case you’re happy with just the looks of it, use a wheel collider without rotation and keep the visual model separate and tilt just that.
     
  3. unity_ECD095A803223483EF8A

    unity_ECD095A803223483EF8A

    Joined:
    Apr 20, 2023
    Posts:
    11
    Yes, but what is the best way to do it?
    - - -
    By using "wheelCol.Get WorldPose" and then applying its values to the wheel mesh, I can't do anything else to the wheel mesh, including adding a Quaternion.Euler to it.
    - - -
    For now, I've come up with this solution: I don't take the rotation from "wheelCol.GetWorldPose". Instead, I assign values to "Quaternion.Euler" via "transform.localRotation", where I send "wheelCol.rpm" and the tilt value.
    - - -
    But with this method, the wheels do not behave quite correctly.
     
  4. tjmaul

    tjmaul

    Joined:
    Aug 29, 2018
    Posts:
    464
    Ah, I see, what about this piece of code:
    Code (CSharp):
    1.     void Update()
    2.     {
    3.         wheelCollider.GetWorldPose(out Vector3 pos, out Quaternion rot);
    4.         transform.position = pos;
    5.         transform.rotation = rot;
    6.         transform.RotateAround(carTransform.forward, tiltAngle);
    7.     }
    This will take the position and rotation from wheel collider and add some tilt angle after that. You obviously have to use the car transform as a reference (or anything else that is not rotated when the wheels turn)