unity-game-enginewheelcollider

How do I get my wheel mesh to rotate on the proper axis?


I have my model setup with wheel colliders and it drives fine. Everything is working well, including the position of the wheel mesh to simulate suspension. My only issue is that when I run the game, my wheels rotate 90 degrees on the Y axis and then roll along sideways. How can I rotate the mesh in the script so that it displays properly? I mainly only need position, but using wheel.getworldpose forces me to use Quaternion and Vector3. Can I do this without using Quaternion?

Heres an Image...

And heres the code Im using to update my wheel position and rotation...

 // Visual updates
    void Update()
    {
        if (!driveable)
        {
            return;
        }

        // SETUP WHEEL MESHES

        // Turn the mesh wheels
        frontLeftWheelWrapper.localEulerAngles = new Vector3(0, 0, steerAngle);
        frontRightWheelWrapper.localEulerAngles = new Vector3(0, 0, steerAngle);

        // Wheel rotation
        frontLeftWheelMesh.Rotate(0, 0, wheelFL.rpm / 60 * 360 * Time.deltaTime);
        frontRightWheelMesh.Rotate(0, 0, wheelFR.rpm / 60 * 360 * Time.deltaTime);
        rearLeftWheelMesh.Rotate(0, 0, wheelRL.rpm / 60 * 360 * Time.deltaTime);
        rearRightWheelMesh.Rotate(0, 0, wheelRR.rpm / 60 * 360 * Time.deltaTime);

        //Wheel Position
        foreach (WheelCollider wheel in m_Wheels)
        {

            Quaternion q;
            Vector3 p;
            wheel.GetWorldPose(out p, out q);

            // Assume that the only child of the wheelcollider is the wheel shape.
            Transform shapeTransform = wheel.transform.GetChild(0);
            shapeTransform.position = p;
            shapeTransform.rotation = q;
        }

Solution

  • I finally solved this by commenting out shapetransform.rotation = q;

    Then I used the original rotation in my script to rotate the wheels, and I used the wheel.getworldpose to update the position.