2D Ground Collision.

D63afd03aea884a4812d1d7360593316
0
Annihilator 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:

d4fca231.png

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

c6573d13.png

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

Please log in or register to post a reply.

6837d514b487de395be51432d9cdd078
0
TheNut 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.

A638aa42130293f319eda7fa4ba121f4
0
fireside 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.

Dd7c9a8bd13bf702acae1b544b44fbd4
0
SolarLune 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.

Fd80f81596aa1cf809ceb1c2077e190b
0
rouncer 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.. :)