# Collision Managers and bitmaps

I am rewriting a game I made to use a (custom) collision manager that uses the minimum displacement method. As of now, my simple manager can only recognize and act on a couple of shapes - Circles and AABB's. Those were pretty simple to implement, but I've run into a problem: My game also needs to be able to have bitmaps that the player (represented by an AABB) can interact with, such as the one below:

I have a couple of questions:

1) Does it make sense to have a shape BitmapShape, which does collision detection at the pixel level and searches outward in the bitmap for a place to move intersecting objects to? In the image above, it would make sense to check the players bottom-center coordinates against the bitmap of the hill, but you can imagine that this would provide odd results for an intersection from the top of the player.

2) How could any system like this allow for a rectangle to move up a hill? Wouldn't an minimum-displacement based method always move the rectangle backwards down a hill?

Thanks

• You might want to look at PMASK - it uses some really clever bitmask stuff to perform a 8x8 over 8x8 detection in one CPU instruction. – Jonathan Dickinson Nov 17 '11 at 20:50

1: That is a very processor consuming scenario, ditch the bitmap to bitmap collision.

2: Correct, minimum displacement would have the player sliding down the hill. What you need is axis-aligned displacement.

Suggestion:
Fill your collision shapes completely, that looks nicer. Make the player collision figure a vertical line, that is so much easier to check against, if you want him to behave like a box you can extend the collision shape to make up for the figures thinness.

In order to perform the actual collision check split you line into 3 sections, perform the check for each of them.

If the figure does not collide with the ground. Or if only the bottom linepart collides with the ground and the figure can be moved upwards vertically so that only a small part of the bottom linepart collide with the ground, without the top linepart intersecting with the ground. Or if it is the opposite case where only the top linepart intersect with the ground. Then it is a legal position.

If the figure does not occupy a legal position, move it backwards towards the position it came from in small steps until it does.

If the figure was moved backwards set it's horizontal movement to 0.

If the figure is in a legal position where only the top or bottom linepart intersect the ground you must move it as described in the collision check.

If the bottom linepart is intersecting and the figure is moving downward you must set it's vertical movement to 0. Likewise if the top linepart is intersecting and the figure is moving upward you must set it's vertical movement to 0.

Note:
The bottom linepart acts as a ground check, if it collides with the terrain the figure is standing on the ground and should therefore be able to jump etc.

• I didn't say ditch pixel-perfect, I said ditch pixel-to-pixel, it is still pixel-perfect. – aaaaaaaaaaaa Sep 10 '11 at 8:27
• I'll try and implement this within the bounds of my framework, but it seems like something that is very hard to abstract out. I'll accept this answer if it ends up working. Thanks – you786 Sep 10 '11 at 20:12
• @yaj786 I presume you made it work. Do you like the solution? Was it easy to implement? The technical side of an answer like this is one thing, writing it up so people understand it quite another. Even though you might not need more input from me, I'd like your thoughts. – aaaaaaaaaaaa Sep 15 '11 at 14:16