Vehicle controller not working well

I am working on a racing game and have an issue with the vehicle controller. When the car gets moving the brake becomes very unresponsive and the car will keep accelerating until it hits something or spins out. The steering continues to work perfectly when moving but the acceleration seems to lock for some reason.

The code:

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum Axel
{
    Front,
    Rear
}

[Serializable] public struct Wheel
{
    public Transform model;
    public WheelCollider collider;
    public Axel axel;
}

public class CarController : MonoBehaviour
{
    private Rigidbody _rigidbody;
    
    [SerializeField] private Transform _centerOfMass;
    [SerializeField] private float motorTorque = 1500f, maxSteer = 20f, breakTorque = 2500f;
    [SerializeField] private List<Wheel> wheels;
    [SerializeField] private bool allWheelDrive = false;
    
    [SerializeField] private bool isBreaking;

    private float horizontalInput, verticalInput;

    void Start()
    {
        _rigidbody = GetComponent<Rigidbody>();
        _rigidbody.centerOfMass = _centerOfMass.localPosition;
    }

    void Update()
    {
        UpdateWheels();
    }

    void FixedUpdate()
    {
        GetInput();
        Move();
        Steer();
    }
    
    void GetInput()
    {
        horizontalInput = Input.GetAxis("Horizontal");
        verticalInput = Input.GetAxis("Vertical");
        isBreaking = Input.GetKey(KeyCode.Space);
    }

    void Move()
    {
        foreach (var wheel in wheels)
        {
            if (allWheelDrive)
            {
                wheel.collider.motorTorque = verticalInput * motorTorque;
                if (isBreaking)
                {
                    ApplyBreaking(breakTorque);
                }
                else
                {
                    ApplyBreaking(0f);
                }
            }
            else
            {
                if (wheel.axel == Axel.Rear)
                {
                    wheel.collider.motorTorque = verticalInput * motorTorque;
                    if (isBreaking)
                    {
                        ApplyBreaking(breakTorque);
                    }
                    else
                    {
                        ApplyBreaking(0f);
                    }
                }
            }
        }
    }

    void Steer()
    {
        foreach (var wheel in wheels)
        {
            if (wheel.axel == Axel.Front)
            {
                var _steerAngle = horizontalInput * maxSteer;
                wheel.collider.steerAngle = Mathf.Lerp(wheel.collider.steerAngle, _steerAngle, 0.5f);
            }
        }
    }

    void UpdateWheels()
    {
        foreach (var wheel in wheels)
        {
            Vector3 _pos;
            Quaternion _rot;
            
            wheel.collider.GetWorldPose(out _pos, out _rot);
            wheel.model.position = _pos;
            wheel.model.rotation = _rot;
        }
    }

    void ApplyBreaking(float breakTorque)
    {
        foreach (var wheel in wheels)
        {
            if (wheel.axel == Axel.Rear)
            {
                wheel.collider.brakeTorque = breakTorque;
            }
        }
    }
}

same here :\

Based on the code provided, it seems that the issue with the vehicle controller is related to the brake torque being too low or not being applied correctly when the car is in motion.

In the Move() method, the brake is applied when the isBreaking variable is set to true, which is determined by the Input.GetKey(KeyCode.Space) method. However, there is no additional logic to reduce the speed or stop the car when the brake is applied. Instead, the ApplyBreaking() method sets the brake torque of the rear wheels to the given value, but this method is only called when the isBreaking variable is true and it only affects the rear wheels.

To fix the issue, you could add additional logic to the ApplyBreaking() method to apply the brake torque to all wheels instead of just the rear wheels. Additionally, you could add logic to reduce the speed or stop the car when the brake is applied, such as reducing the motor torque or applying a force in the opposite direction of motion.

Alternatively, you could try increasing the brake torque value to make the brake more responsive when the car is in motion. You could also try adjusting the Mathf.Lerp() method in the Steer() method to ensure that the steering angle is updated correctly and smoothly.

Overall, it may take some experimentation and tweaking of the code to find the best solution for your specific racing game.

(Thanks chatGPT hahaha).