My code is right but the movement is very strange

Hello there, i created patrol enemy so whenever player touch the edge collider, it will turn direction here is my code :

     class Enemy{

private bool facingRight;
    void Start()
            {
                facingRight = true;
            }
    void Update()
    {
    Move();
    }
    public void Move()
        {
            Vector2 moveDirection = facingRight ? Vector2.right : Vector2.left;
            transform.Translate(moveDirection * (movementSpeed * Time.deltaTime));
        }
    
      void OnTriggerEnter2D(Collider2D other)
        {
            if (other.tag == "Edge")
            {
                enemy.ChangeDirection();
            }
        }
    
        public void ChangeDirection()
            {
                facingRight = !facingRight;
                transform.localScale = new Vector3
                    (transform.localScale.x * -1, 1, 1);
            }
    }

I have already try to debug both on facingright condition and everything is correct also debug moveDirection variable , it’s correct when the collide with right edge, they will get vector2.left

But i tried to run my game it’s strange when they collide with right edge , enemy still run to to the right.

If you can help me to solve my issue , I will be glad , Thanks.

Good day.

Think a little.

First, you use Transalte, which is a function to move a object from its"view", so using vector3.right or left or up or all this vectors, are relative to the object rotation.

You do one more thing when hit the collider… You turn the gameobject, so now, left side is the old right side… If you do this:

 (transform.localScale.x * -1, 1, 1);

dont need to change the vector.

Bye!