Car wheels turning backwards after half rotation?

Hi

I have a script to make the front wheels on my car move forward but when they spin around it z axis goes from 0 - 180 and they turn back the other way and I cant work out why it is doing that?

Here is a gif of my problem that im having.
I added the script to gokart3 Imgur: The magic of the Internet

This my c# code

Well for starters I’d be using a WheelCollider.

It looks like something funky is going on with gimbal locking/scale in the heirarchy.

Try changing your code to this:

    public Transform[] wheels;
    public float wheelsRotationSpeed = 2f;

    Quaternion[] originalRotations;
    float rotation;

    void Start()
    {
        for(int i = 0; i < wheels.Length; i++)
        {
            originalRotations[i] = wheels[i].transform.rotation;
        }
    }

    void Update()
    {
        rotation += Time.deltaTime;
        for(int i = 0; i < wheels.Length; i++)
        {
            wheels[i].transform.rotation = originalRotations[i] * Quaternion.Euler(rotation, 0f, 0f);
        }
    }

thanks for the help

I gave that a go but got this error with no wheels spinning at all


and I also get the error

Oh whoops, add this to Start, before the for loop:

originalRotations = new Quaternion[wheels.Length];

ok I think that works now but the only problem is the wheels turn very very slowly no matter how high I set the wheel rotation speed

Sorry, wrote it in the forums editor.
Multiply the Time.deltaTime by the rotation speed:

rotation += Tmie.deltaTime * wheelsRotationSpeed;

thank you finally got it working