Rotate a moving object without changing its direction

I have a box that I can move around with WASD. When I use A or D to rotate, it’s as if I were turning a steering wheel - the direction of the movement changes. I only want the direction to change when pressing W (the box’s “engine” is turned on), otherwise I just want the box to rotate but continue in the same direction it was going. Here is my movement code:

public float speed = 1.0F;
	public float current_speed = 0.0F;
	public float max_speed = 2.0F;
    public float rotationSpeed = 100.0F;
	
	// Update is called once per frame
	void Update () {
		
		float translation = 0.0F;
		if(Input.GetAxis("Vertical") > 0)
		{
		    translation = current_speed + Input.GetAxis("Vertical") * speed;
			
			if(translation > max_speed)
				translation = max_speed;
			
			current_speed = translation;
		}
		else if(Input.GetAxis("Vertical") < 0)
		{
			translation = current_speed - speed*.1f;
			if(translation < 0.0f)
				translation = 0.0f;
			current_speed = translation;
		}
		else if(current_speed > 0.0F) {
			translation = current_speed - speed*.05F;
			current_speed = translation;
		} 
		
        translation *= Time.deltaTime;
        
		float rotation = -1*Input.GetAxis("Horizontal") * rotationSpeed;
		rotation *= Time.deltaTime;
        transform.Translate(0, translation, 0);
        transform.Rotate(0, 0, rotation); 
	}

I have successfully done this in a 3D project using C#. You rotate the object relative to itself and you move the object in the direction you want it to go relative to the world coordinates.

If you rotate an object and then also move relative to its local position, or its own position, its forward facing direction will change when rotating and it will then move in the new direction which in this case is undesirable.

Below is sample code that works for 3D. The gameObject with a RigidBody continuously moved in a single direction while rotating on it’s y axis. As it is in the FixedUpdate method used for physics you can also change it and it will apply the change, if you wanted to move in a new direction because of user interaction. I think you should be able to get this to work for 2d objects just leave the z axis at zero as it’s not used in 2d. But use specific 2d physics methods/functions as much as you can in a 2d game as 3d physics calculations (even with the z axis at 0) causes some extra overhead.

void FixedUpdate()
	{
		transform.Rotate(0,rotationSpeed*Time.deltaTime,0,Space.Self); //rotate
        transform.Translate (directionSpeed*Time.deltaTime,0,0,Space.World);  //move 

	}

I’d say: make the render a child GameObject (so that it’s rotation doesn’t affect rigidbody’s rotation) then keep that rotation in a separate variable, then when the player presses forward apply a force/acceleration in the correct direction to the rigidbody.