[Solved] How to make goalKeeper move within post but not move towards to the player?

YouCanCallMe Syarif Asks: 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)
enter image description here


enter image description here

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 :

Code:
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)
                {
                    //Animation
                    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?

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.