# How to make one-way collision

Hi, someone know the algorithm to make one-way collisions with 2 rects? It’s the collision did like in old mario’s games and in doodle jump. I’m making a jump game and I don’t know how to make this.
Thanks for any help.

Do you mean the kind of platforms (in Super Mario-games) that Mario can jump through from under the platform and then can stand on top of it?
Platform: http://themushroomkingdom.net/images/remakes/smb/smb_w4-3.png

Okey, bad example in my earlier post, since Mario can’t jump through those platforms.

[quote=“Naith”]Okey, bad example in my earlier post, since Mario can’t jump through those platforms.

It’s exactly what I need. I tried an ugly code and works, but when the player go from horizontal sides to the platform, so he is put abruptly on up side. Then, I created a new code with a current platform and solved the problem, but when the player go from horizontal sides jumping so he is put abruptly on up side.

I don’t know how to do this, if you know how to do this, please, help me.

Sorry for late answer. I’m afraid I don’t have enough knowledge when it comes to one-way platforms but I googled some for you and found this site:
http://www.gamedev.net/page/resources/_/technical/game-programming/the-guide-to-implementing-2d-platformers-r2936
Scroll down on the page and you’ll find a short text about one-way platforms and how to think when developing it.

As has been written on the page, you shouldn’t check for collision on the x-axis, since the tile is never an obstacle.

So what you should probably do is, whenever the player is jumping and the collision rectangle (let’s call it Player_Rectangle) is colliding with the tile’s collision rectangle (let’s call it Tile_Rectangle), check if the Player_Rectangle’s lowest part is 1 pixel above the Tile_Rectangle’s highest part, ie, check if Player_Rectangle.y + Player_Rectangle.h < Tile_Rectangle.y.
If this is the case, make sure that the player is stopped when falling down (due to gravity).
The reason you’re gonna check the above situation is that the player should be able to jump into the tile, from below, and then fall back down if the player doesn’t jump high enough to reach above the tile.

I’m not very good in explanations but I hope you’ll understand what I’m trying to say.

Okay, thank you for the link. I made some weird code and got the right “answer”, it isn’t that I’ll show here but works “perfectly”.
Thank you for the explanation.

I don’t really know what you mean. Though. you could allways create small rectangles to put on fixed positions of your objects. Then calculate if the rectangles overlaps each other!

maoski21, I just used two rects and a vector of rects with no collision and solved the problem, for me, an ugly solution.