Hi guys,
I feel like a complete rookie asking a question about collision detection but I'd like to hear what your experience is on this. (Also writing posts is kind of therapeutic)
I have a 2D platform game where all objects have a collision map. I figured that it's better to test on a consistent map than having pixel perfect collision detection on every animated frame.
Here's an example spritesheet:
And here's the collision map:
There is one hit area for crawling and one for crouching and one for everything else.
Now, is this a normal way to solve the collision detection problem? This works fine at the moment but now I'm going to implement a ledge hanging algorithm. My plan for this is to add a couple of green pixels on the right-most hit area that only is checked for when the player is jumping so that I know if he's in grabbing distance.
Come to think of it I've got a bunch of other problems too. If you look at the crawling hit map it's possible to hang by the edge of your feet if you crawl out far enough off an edge. I've solved that with some patchy code that will force you into kneeling but I would like to have a more generic solution for this.
While writing I figure that perhaps I should use
a green color the G channel for areas that can support the character. Like this...
That way I can make sure that the character is not balancing too far off an edge and I can check for hanging on a ledge.
Anyone else got any useful tips?
EDIT:
I'm going to use yellow for pixels that both support the character and can be hit for damage. The R channel will be used for hit detection against enemies while the G channel will be used for checking if the character is standing or hanging on something.
EDIT:
Fixed the second hit map