Jump to content


2D Ground Collision.


4 replies to this topic

#1 Annihilator

    New Member

  • Members
  • PipPip
  • 10 posts

Posted 13 March 2011 - 10:57 PM

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:

Posted Image

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

Posted Image

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.
Technical Director, Engine Programmer.
ANN-Tech. Team.

http://www.ann-tech.com
https://twitter.com/#!/ANNTechTeam

#2 TheNut

    Senior Member

  • Moderators
  • 1699 posts
  • LocationThornhill, ON

Posted 14 March 2011 - 02:29 AM

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.
http://www.nutty.ca - Being a nut has its advantages.

#3 fireside

    Senior Member

  • Members
  • PipPipPipPip
  • 1587 posts

Posted 14 March 2011 - 02:35 AM

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.
Currently using Blender and Unity.

#4 SolarLune

    New Member

  • Members
  • Pip
  • 2 posts

Posted 20 March 2011 - 11:49 PM

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.

#5 rouncer

    Senior Member

  • Members
  • PipPipPipPip
  • 2722 posts

Posted 21 March 2011 - 05:43 AM

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.. :)
you used to be able to fit a game on a disk, then you used to be able to fit a game on a cd, then you used to be able to fit a game on a dvd, now you can barely fit one on your harddrive.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users