Does anybody have any tutorials/tips about the logic of platformer collision detection, as opposed to the programming?
It seems like most tutorials I manage to google are just working through programming it, and they don't fully explain the logic of "You need x to happen, so you want your code to do y because z".
I'm working on a platformer but my code has become spaghettis and is causing some problems with limited functionality, so I'm planning on rebooting it and I'd like to improve it when I do.
Currently: All immovable tiles are built around a 32x32 grid; I have a hash table (python's dictionary) that stores the location of each. Every frame, movable objects check the dictionary for the tiles they want to move into, and detect a collision if there's a block there. If they can move, they then iterate through every object and if close enough (checks x then y difference) it runs a function which handles all collision, like;
if object1 == "hero":
if object2 == "bullet": do x
elif object2 == "enemy1": do y
Iterating through every object is pretty slow but I can't think of a way to solve it except to put every object in a dictionary based on its location (and two objects will only check for collision if they're in the same large (256x256?) grid square) - and this a problem because it means I then have to make objects keep checking and see if they're moving into a different grid square.
Basically I'd like a simple overview of a better method that doesn't require n^2 (or n!, but that would be a pain given the way it's written) collision checks every frame.
Posted Mar 15, 2012, 10:12 AM UTC