Moving platform grab the player

Many threads concerning moving platform with this kind of code :

  private void OnCollisionEnter2D(Collision2D other)
    {
        if (other.gameObject.tag == "MovingPlatform")
        {
            transform.parent = other.transform;
            onPlatform = true;
        }
    }

    private void OnCollisionExit2D(Collision2D other)
    {
        if (other.gameObject.tag == "MovingPlatform")
        {
            transform.parent = null;
            onPlatform = false;
        }
    }

the code works very well, but if the player has the same “height” 177541-2021-03-15-10h46-04.png, when the platform moves right, the player is attached to the platform, and stick to it. platforms push and pull the player. Push is cool, but not pull :confused:

Finally with a detection of the position (y axis) of the player :

if (other.gameObject.tag == "MovingPlatform" && transform.position.y > other.gameObject.transform.position.y) { transform.parent = other.transform; onPlatform = true; }