Collision in this tutorial

I’m working on this tutorial for a while. All is well except that when there is a collision between player and my flag the player not pushes the flags must not leave the borders. What to do it? thank you.