Moving into a squarre grid in 8 directions ?

Hi there !
I’m currently struggling with my moving feature wich must move in 8 directions in a grid.
like that :


Currently it is moving on the red arrows but i want it to move on red & green ones and still beiing into the grid.

For now the C# i’m using look like this :

    private void Update()
    {
        if (moving)
        {
            if (Vector3.Distance(startPosition, transform.position) > 1f)
            {
                transform.position = targetPosition;
                moving = false;
                return;
            }

            transform.position += (targetPosition - startPosition) * moveSpeed * Time.deltaTime;
            return;
        }

        if (Input.GetAxisRaw("Vertical") == 1f)
        {
            targetPosition = transform.position + Vector3.forward;
            startPosition = transform.position;
            moving = true;
        }
        else if (Input.GetAxisRaw("Vertical") == -1f)
        {
            targetPosition = transform.position + Vector3.back;
            startPosition = transform.position;
            moving = true;
        }

        if (Input.GetAxisRaw("Horizontal") == 1f)
        {
            targetPosition = transform.position + Vector3.right;
            startPosition = transform.position;
            moving = true;
        }
        else if (Input.GetAxisRaw("Horizontal") == -1f)
        {
            targetPosition = transform.position + Vector3.left;
            startPosition = transform.position;
            moving = true;
        }
    }

I’m open to every solutions and if you know a good tutorial to do this as well i’ll take it.
Thank you in advance for your help :slight_smile:

Something has gone very wrong with your picture upload above.

You might want to try some googling first:

6848030--797522--Screen Shot 2021-02-17 at 10.41.56 AM.png