0
101 Mar 13, 2011 at 22:57

Hi everyone!

Just looking for a quick advise on Ground collision for a basic
2D Platform Game.

For a flat surface it is easy to check collision as we only need to
check for Rectangle to Rectangle Collision like on this picture:

But how would you do that when level ground is
not even, like in this picture:

So, if anyone has a good advice on how to approach this, please let me know,and i am sure it will be helpful not just for me.

Thanks a lot for your time.

#### 4 Replies

0
179 Mar 14, 2011 at 02:29

In Worms type games you generate a monochrome bitmap where black represents ground or obstacles and white represents open space. You then perform pixel checks in the monochrome bitmap to find the floor or obstacles. If your game is a side-scroller, you can save considerable memory by just storing a single Y-value along the x-axis, which will represent your floor. It’s a very fast look-up formula f(x) = y. You can use standard sphere or box collision tests for the other entities in the game.

0
141 Mar 14, 2011 at 02:35

I’ve never done this. You could do a search for per pixel collision or maybe someone here can explain it.

Or you could divide the terrain into smaller sections of straight line slopes. Each of these smaller sections would comprise a rectangle. The straight line between the lower corner of the rectangle and the upper corner of the rectangle would have a slope, so you could use y=mx+b to find a collision point in between after first testing for rectangular collision.

Hmm. theNut beat me to it. So that’s per pixel.

0
101 Mar 20, 2011 at 23:49

Hey. This is my first post here, so don’t mind me if my post is stupid. I did a technique like TheNut, where you have a single image representing the level collision data, which isn’t the normal level ‘color’ data. Then, you check each pixel to see if its alpha is greater than 0 - if so, then there’s ground or a wall in that position.

0
103 Mar 21, 2011 at 05:43

Then you could make the sprite escape to the closest possible position that is in air, and that would work for caves, walls and the ground yes.

Ive actually done that before myself also.

I like your wicked trees btw.. :)