Different Solution to Switch Enemy Direction

To switch the enemy direction, I used this instead:

    private void OnTriggerExit2D(Collider2D sensorCollider) 
    {                          // Enemy, change direction at end of ground.
        FlipEnemyFacing();
        moveSpeed = -moveSpeed;
    }

    private void FlipEnemyFacing()  // Flip Enemy X scale (sprite, colliders, etc.)
    {
        transform.localScale = new Vector2(-Mathf.Sign(myRigidBody2D.velocity.x), 1f);
    }

Jim

2 Likes

There’s always another way.

Privacy & Terms