Search Unity

Wheel Collider Extra Camber Angle

Discussion in 'Physics' started by Ceylan12, Sep 13, 2020.

  1. Ceylan12

    Ceylan12

    Joined:
    Dec 24, 2016
    Posts:
    113
    Hello, I want to add customization selections for my game like camber. I dont know how can I make it?
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,508
    The WheelCollider itself can only be vertical with respect to the rigidbody it belongs to. You could only define pose of the visual wheel yourself to make it look like it has camber.
     
  3. Ceylan12

    Ceylan12

    Joined:
    Dec 24, 2016
    Posts:
    113
    Thank you for answer Edy,
    Code (CSharp):
    1. public void ApplyLocalPositionToVisuals(AxleInfo axleInfo)
    2.     {
    3.         Vector3 position;
    4.         Quaternion rotation;
    5.         Vector3 camberAxle = transform.right;
    6.         axleInfo.leftWheelCollider.GetWorldPose(out position, out rotation);
    7.         axleInfo.leftWheelMesh.transform.position = position;
    8.         axleInfo.leftWheelMesh.transform.rotation = rotation * Quaternion.Euler(-camberAxle*camberAngle);
    9.         axleInfo.rightWheelCollider.GetWorldPose(out position, out rotation);
    10.         axleInfo.rightWheelMesh.transform.position = position;
    11.         axleInfo.rightWheelMesh.transform.rotation = rotation * Quaternion.Euler(camberAxle*camberAngle);
    12.     }
    I tried to make it with this code but it is wobbling. I don't know why. Can you help me about it please?
     
  4. AugGust

    AugGust

    Joined:
    Mar 7, 2014
    Posts:
    9
    Hi just a thought when I read this (meeting a similar problem), how about putting each wheel into a parent object, and tilting the parent instead?

    My idea is like this, for each update:
    1. Set rotation of parent to aligned with rigidbody
    2. Set wheel transform position and rotation
    3. Tilt parent object to desired camber angle
     
    Ceylan12 likes this.
  5. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,508
    @Ceylan12 I don't know, maybe it's about the quaternion multiplication not being commutative (order matters).

    @AugGust It won't work. The WheelCollider will be vertical with respect to the Rigidbody it belongs to, no matter the intermediate hierarchy.
     
    driftnumata and Ceylan12 like this.
  6. Ceylan12

    Ceylan12

    Joined:
    Dec 24, 2016
    Posts:
    113
    I tried this way but didn't work thank you anyway I solved it.
     
  7. Ceylan12

    Ceylan12

    Joined:
    Dec 24, 2016
    Posts:
    113
    It look really sensible, I didn't try it maybe it could solve my problem. I created another parent for camber and set the parent angle to this object. It worked. Thank you very much.
     
  8. AugGust

    AugGust

    Joined:
    Mar 7, 2014
    Posts:
    9
    I was thinking about the "visual only" object, not the wheel collider. Cool maybe i'll try what Ceylan said, the cars look weird with 0 camber