How to make GoalKeeper move within post but not move towards to the player?

Hello so basically I make a 2d top-down soccer game but I have to trouble with GK AI, I want to GK is followed the ball but not move toward on it

let say (Enemy = GK)
so when the player moves to the left or right the enemy will follow to the right or left not The Yaxis but in X-axis with guarding the post or Y=0

my default enemy movement is like this :


if (gameObject.CompareTag("GK"))

            anim.SetBool("GKRun", false);
            gkballInRange = Physics2D.OverlapCircle(transform.position, gkballRange, playerMask);
            float distancePlayer = Vector2.Distance(target.position, transform.position);

            if (gkballInRange)
                if (distancePlayer <= gkballRange)
                    anim.SetBool("GKRun", true);
                    transform.Translate(0, -speed * Time.deltaTime, 0);


in that scrip, when the ball is on the range the GK is moving to the ball just that. maybe anyone can explain to me how to do it?

The problem is that you are Translating in the Y-axis instead of the X-axis. The translate method adds values in this order (x , y , z)

So the issue is here:

//Problematic line

//You should be doing