Car control question (direction/movement/acceleration)

Greetings !

Currently I am working on a Unity top-down 2D simulator game with a car to drive in the city.
In order to move the car I use this code :

public class car_move1 : MonoBehaviour

{

[SerializeField]

private float speed;

[SerializeField]

private float rotationSpeed;

void Update()

{

float horizontalInput = Input.GetAxis("Horizontal");

float verticalInput = Input.GetAxis("Vertical");

Vector2 movementDirection = new Vector2(horizontalInput, verticalInput);

float inputMagnitude = Mathf.Clamp01(movementDirection.magnitude);

movementDirection.Normalize();

transform.Translate(movementDirection * speed * inputMagnitude * Time.deltaTime, Space.World);

if (movementDirection != Vector2.zero)

{

Quaternion toRotation = Quaternion.LookRotation(Vector3.forward, movementDirection);

transform.rotation = Quaternion.RotateTowards(transform.rotation, toRotation, rotationSpeed * Time.deltaTime);

}

}

}

The question is, how to separate car rotation with its movement and add an acceleration, and all that by using separate keys. For example , arrow keys , ASDW and joystick on gamepad shall rotate, and 2 other keys will accelerate/move and break/stop the car (to be accurate let’s take left and right triggers on gamepad).

By this post/message I’m not requesting/asking for a direct code, but if you please direct me, my thoughts to find out the solution.

Thank you

I think you overcomplicate the topic, below example is for 3D but should be easily adapted for 2D.

Thank you