Image Based Collisions for 2D Platformer

Blitz3D Forums/Blitz3D Programming/Image Based Collisions for 2D Platformer

ClayPigeon(Posted 2011) [#1]
I am creating a 2D platformer and I would like the collisions in the game to not be tile based, but be image based. In other words, I will have an image in which white is 'no collision' and black is 'collision'. I have a 32x32 black square image for the player's bounding box and the 640x480 image for the world collisions. I'm using the ImagesCollide() function to perform collision checking. The only problem is that I can't figure out how to do the collision response. If I simply move the player back to its previous position if there is a collision (never works :D), it sort of hovers above the ground a little. So does anyone know how to perform a collision response with an image? I know it's possible...


6(Posted 2011) [#2]
As far as I understand it, collision detection should be performed before an object is moved. So when the player hits a key to move a character you calculate the outcome of moving in that direction and if a collision doesn't occur, you then move the character.


ClayPigeon(Posted 2011) [#3]
if a collision doesn't occur, you then move the character.


But, if the collision does occur, you need to move it as close to the collision as you can without actually invoking the collision. This is necessary because if the object is moving quickly, it would stop far before it actually ever made the collision.

collision detection should be performed before an object is moved.


This, though I have found to be true.

Last edited 2011


Yasha(Posted 2011) [#4]
If a collision occurs, you could put it back where it was an increment it in steps of one pixel (or some kind of optimisation involving a binary chop) towards the desired position? Then when it collides again, stop moving it.


ClayPigeon(Posted 2011) [#5]
But the problem is that when the player is on an upward slope, and the 'right' key is held, they will not go up it (I think) Instead they will walk into it as though it is a vertical wall. (once again this is a theory)