Collision Detection

Hey there.
I’m currently thinking of an algorithm for a collision detection.
I want to implement various tile-collisions…

  public static final byte COLL_THROUGH = 0;
  public static final byte COLL_SOLID = 1;
  public static final byte COLL_SLOPE_R = 2;
  public static final byte COLL_SLOPE_L = 3;
  public static final byte COLL_12SLOPE_R = 4;
  public static final byte COLL_22SLOPE_R = 5;
  public static final byte COLL_12SLOPE_L = 6;
  public static final byte COLL_22SLOPE_L = 7;
  public static final byte COLL_14SLOPE_R = 8;
  public static final byte COLL_24SLOPE_R = 9;
  public static final byte COLL_34SLOPE_R = 10;
  public static final byte COLL_44SLOPE_R = 11;
  public static final byte COLL_14SLOPE_L = 12;
  public static final byte COLL_24SLOPE_L = 13;
  public static final byte COLL_34SLOPE_L = 14;
  public static final byte COLL_44SLOPE_L = 15;
  public static final byte COLL_STAIR_R = 16;
  public static final byte COLL_STAIR_L = 17;
  public static final byte COLL_14 = 18;
  public static final byte COLL_24 = 19;
  public static final byte COLL_34 = 20;
  public static final byte COLL_WATER_SURFACE = 21;
  public static final byte COLL_UNDERWATER = 22;

Here for a graphical visualisation:

https://dl.dropboxusercontent.com/u/13341521/TestTileset.png

Does someone have an Idea how I should start with this?
I’ve never done something like that before…

You need to figure a way to detect collision in a triangle. Since all shapes are made up of triangles, you can then detect collision in any shape. I don’t know how to detect collision in triangle, sorry. But it’s a start :smiley:

I’d not go with the triangle shape, these are pixel perfect in my opinion. Simply save the height at each pixel on the x-plane and do pixel perfect collision after you’ve culled the obvious collisions (those that don’t even fit inside a full rectangle).

You can easily get the height if, for instance, your images are fully transparent on places you don’t want covered (or any other color you decide is your “background color” or whatever) by looping through the image and checking the height of each pixel that is part of the shape and if it’s higher than the one stored already then overwrite it etc.

Make polygons, and use ShapeIntersect for collisions. If you ask me.

make more then one rects for one image and detect for all of them togeter i think it will work try it out then msg me :smiley:

If they are tiles like you’ve shown and they’re pixel perfect you really need pixel perfect collision or it’s going to look weird with polygons or shapes as collision masks.

Since all of the tiles you’ve shown are filled bottoms up you can simply store the height of each pixel on the tile and use that information when testing collisions with objects on the tile.

However, if your levels are made up of a lot of big polygons (like soldat.pl e.g.) then obviously this tile based pixel perfect method is a complete waste of time.

Look at my project (Perils of Alchemy, it’s somewhere in the forum and I’m being lazy). Also, you can look at: http://info.sonicretro.org/SPG:Solid_Tiles which has a lot of information about doing tile based collisions.