My car is moving on an axis

public class CarController : MonoBehaviour
    private const string Horizontal = "Horizontal";
    private const string Vertical = "Vertical";

    public float horizontalInput;
    public float verticalInput;

    public float speed;
    Vector3 rotateRight = new Vector3(0, 30, 0);
    Vector3 rotateLeft = new Vector3(0, -30, 0);
    [SerializeField] private float motorForce;
    [SerializeField] private Rigidbody rb;
    [SerializeField] WheelCollider frontRight;
    [SerializeField] WheelCollider frontLeft;
    [SerializeField] WheelCollider rearRight;
    [SerializeField] WheelCollider rearLeft;
    private void FixedUpdate()


    private void HandleMotor()
        if (Input.GetKey(KeyCode.W))
            transform.position += Vector3.forward * speed * Time.deltaTime;
        if (Input.GetKey(KeyCode.S))
            transform.position += Vector3.back * speed * Time.deltaTime;
    private void HandleSteering()
        if (Input.GetKey(KeyCode.D))
            Quaternion deltaRotationRight = Quaternion.Euler(rotationRight * Time.deltaTime);
            rb.MoveRotation(rb.rotation * deltaRotationRight);

        if (Input.GetKey(KeyCode.A))
            Quaternion deltaRotationLeft = Quaternion.Euler(rotationLeft * Time.deltaTime);
            rb.MoveRotation(rb.rotation * deltaRotationLeft);


This is my current code, when moving forwards and backwards as well as left and right, it moves and turns on the axis. However, this means that when i turn, my car still moves along the axis whilst facing a different direction.

Is anyone able to help?

I’m confused. You are mixing different methods of simulating car movement.

Your car has a Rigidbody and WheelColliders (which makes me think you want to use physics), yet you are moving the car directly using transform.position which ignores physics completely.

I recommend that you watch a couple of video tutorials on how to use WheelCollider.

If you want to know why the car is moving irrespective of its rotation (the direction it’s facing), it’s because you’re using:

transform.position += Vector3.forward ...;

You’re telling it to move the car along the world Z-axis. I say Z-axis because Vector.forward is (0, 0, 1) (x, y, z).

To move an object forward relative to itself without physics (warning: this can make it go through other colliders):

transform.Translate(Vector3.forward * speed * Time.deltaTime, Space.Self);

Since you have a Rigidbody (and I assume isKinematic is false), try pushing it forward by using AddRelativeForce():

rb.AddRelativeForce(Vector3.forward * someForce);

Adjust the someForce value until it starts to affect the car.