Move and rotate X or Z axis but not diagonally!

Hello guys I’m new to programming and I have the following issue:

My player is a tank and I want this tank to be able to move and rotate to the direction is moving and keep that rotation till the player changes direction on the X an Z axis but not diagonally!
The inspiration for this movement comes from an old SNES game named Battle City . My script looks as follows:

public class PlayerController : MonoBehaviour
{
public float speed = 2f;
public GameObject bulletPrefab;
public Transform fireBullet;
bool isReadyToInstantiate;

// Start is called before the first frame update
void Start()
{
    isReadyToInstantiate = true;
}

// Update is called once per frame
void Update()
{
    float horizontalInput = Input.GetAxis("Horizontal");
    float verticalInput = Input.GetAxis("Vertical");

    Vector3 moveDirection = new Vector3(horizontalInput, 0, verticalInput);
    moveDirection.Normalize();

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

    if(moveDirection != Vector3.zero)
    {
       transform.forward = moveDirection;
    }

    if (isReadyToInstantiate && Input.GetKeyDown(KeyCode.Space))
    {
         StartCoroutine(PreventSpam());
         Instantiate(bulletPrefab, fireBullet.position, fireBullet.rotation);
    }
}

IEnumerator PreventSpam() 
{
    isReadyToInstantiate = false;
    yield return new WaitForSeconds(1);
    isReadyToInstantiate = true;
}

You should review this tutorial. Unity Connect
But basically, you want to use Vector3.forward to move in the direction your tank is pointing.
Unity - Scripting API: Transform.forward shows you how and shows how to rotate also.
Have fun.

first thing that came to mind:

        float horizontalInput = Input.GetAxis("Horizontal");
        float verticalInput = Input.GetAxis("Vertical");
        Vector3 moveDirection = Mathf.Abs(horizontalInput) > Mathf.Abs(verticalInput) ? Vector3.right * horizontalInput : Vector3.forward * verticalInput;

        // Or more readable

        if (Mathf.Abs(horizontalInput) > Mathf.Abs(verticalInput))
        {
            moveDirection = Vector3.right * horizontalInput;
        }
        else
        {
            moveDirection = Vector3.forward * verticalInput;
        }

I’ve finally got a solution for my problem with the following modifications :

void Start()
{
isReadyToInstantiate = true;
}

// Update is called once per frame
void Update()
{
    float horizontalInput = Input.GetAxis("Horizontal");
    float verticalInput = Input.GetAxis("Vertical");

    Vector3 moveDirection = new Vector3(horizontalInput, 0, 0);
    Vector3 moveDirection2 = new Vector3(0, 0, verticalInput);
    

    moveDirection.Normalize();

    if (moveDirection != Vector3.zero)
    {
        transform.forward = moveDirection;
        transform.Translate(moveDirection * speed * Time.deltaTime, Space.World);

    }
    else if (moveDirection2 != Vector3.zero)
    {
        transform.forward = moveDirection2;
        transform.Translate(moveDirection2 * speed * Time.deltaTime, Space.World);

    }
  
    if (isReadyToInstantiate && Input.GetKeyDown(KeyCode.Space))
    {
         StartCoroutine(PreventSpam());
         Instantiate(bulletPrefab, fireBullet.position, fireBullet.rotation);
    }

}

IEnumerator PreventSpam() 
{
    isReadyToInstantiate = false;
    yield return new WaitForSeconds(1);
    isReadyToInstantiate = true;
}