so I'm building up a simple arcade racing game and I was messing around with the Wheel Colliders setup. I was wondering if it was possible to add some camber adjustments in real time depending on the maximum length of the suspension travel. I managed to achieve this by parenting the mesh, rotating it locally by the actual wheel rotation and rotating the parent by the desired camber angle.

It's supposed to be like this: at maximum suspension length (like, in the air when jumping) I'm expecting a positive camber, at rest point (grounded on a flat plane) I'm expecting a 0deg camber and if the suspension is compressed I'm expecting a negative camber.

Everything seems to work but when the car changes direction it doesn't work anymore.

This is a snippet of what I'm doing to achieve this:

    frontAxle.leftWheel.GetWorldPose(out Vector3 frontLeftWheelPosition, out Quaternion frontLeftWheelRotation);
    frontAxle.leftWheelMesh.transform.position = frontLeftWheelPosition;
    frontAxle.leftWheelMesh.transform.rotation = Quaternion.Euler(0, 0, frontLeftCamberAngle);
    frontAxle.leftWheelMesh.GetChild(0).transform.localRotation = frontLeftWheelRotation;

Don't mind the spaghetti code, I'm looking to clean it up as soon as I get things working

enter image description here

I hope you can help me, this problem is driving me crazy

  • 1
    \$\begingroup\$ It's odd to mix .rotation and .localrotation the way you've shown here. Are you able to revise this to work entirely with local rotation? This will keep it invariant no matter how the car is rotated in the world. \$\endgroup\$
    – DMGregory
    Commented May 25 at 11:55
  • \$\begingroup\$ I already tried that, using both localRotation solves the problem but now if the car changes direction the wheels spin on the x axis based on cars' direction \$\endgroup\$
    – Danilolilo
    Commented May 25 at 12:50
  • 2
    \$\begingroup\$ I think we might need a more complete view of your setup, then. Can you walk us through the steps to create a Minimal Complete Verifiable Example of the problem, starting from an empty scene? Once we can reproduce your car structure, we can test potential fixes to be sure they'll work for you. \$\endgroup\$
    – DMGregory
    Commented May 25 at 13:07


You must log in to answer this question.

Browse other questions tagged .