I have a character that you can move up, down, left, and right from a view looking down on the character. Making him not leave the scene was easy. Now though, I am trying to put a square obstacle in the middle of the scene, that the character can not walk on. I'm missing something simple that I can't put my hands on.

For the walls, when you hit the wall, it sets your x coordinate back outside, so you can still run along the walls but not go out. With this square, you can't use that same method. It doesn't know if you're running from the left, right, or bottom, or sometimes two of these. If you tell it to move you to the left of the obstacle, it only works correctly if you run into it from the left. If you hit it from the bottom, it jumps you over to the left of it.

Is there any simple way to make it so that a character cannot walk in a certain area in the middle of the screen?