Wheel Colider Problem on tires

Hi

Im having problems with the wheel coliders I have created for the tires I have. I have wheel colliders on all four tires and have a script that allows me to move the car but when I press play the front wheels turn right and the back wheels seperate from where they are meant to be.

Im not sure if it has anything to do with the box coliders I have set up on the car.


This is the code I have that makes the car move.

using System.Collections;
using UnityEngine;

public class Car : MonoBehaviour
{
    public float maxTorque = 50f;

    public WheelCollider[] wheelColliders = new WheelCollider[4];
    public Transform[] tireMeshes = new Transform[4];

    void Update()
    {
        UpdateMeshesPositions();
    }

    void FixedUpdate()
    {
        float steer = Input.GetAxis ("Horizontal");
        float accelrate = Input.GetAxis ("Vertical");

        float finalAngle = steer * 45f;
        wheelColliders [0].steerAngle = finalAngle;
        wheelColliders [1].steerAngle = finalAngle;

        for (int i = 0; i < 4; i++)
        {
            wheelColliders[i].motorTorque = accelrate * maxTorque;
        }
    }

    void UpdateMeshesPositions()
    {
        for(int i = 0; i < 4; i++)
        {
            Quaternion quat;
            Vector3 pos;
            wheelColliders[i].GetWorldPose(out pos, out quat);

            tireMeshes[i].position = pos;
            tireMeshes[i].rotation = quat;
        }
    }
}

I am stumped as to why this is doing it cause all the wheels are set to 0 on the z axis same with all the wheel coliders. plus I have also tried siing them up and down to see if that makes any difference.

That does seem weird. Things to check: Do you have any colliders or rigidbodies on the wheel meshes? You shouldn’t. Are all the wheel meshes the same, and are they centred correctly? Try changing the tool handle mode from ‘center’ to ‘pivot’ to check where the 0-point of an object is.

I don’t think it has to do with your box colliders, the wheel collider gizmos are in the right place, so they are not getting moved around, and if all your go-kart’s colliders are children of the same rigidbody they won’t affect each other anyway.

I think there was problems with the rear tires so i just duplcated the front tries and used them and that seemed to fix that from moving

but I still have a problem of the front tires turning to the left and the kart tilting to the right

Then when I turn down the mass on the rigidbody it does this

Hmmm, could you share a screenshot of one of the wheel colliders and one of the wheel meshes, how they are set up in the inspector?

It looks like you might have some extra rigidbodies attached to your car somewhere. You should only have a single rigidbody, the one on the “Go Kart2” object.

Wheel Collider

Wheel Mesh

Go Kart

Here is the project file to take a look
http://ge.tt/73YNbdl2