[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Help needed with basic 2D collision detection



Hi all,

Recently started learning Python (my first experience with a programming language since actionscript back in the time of Flash 5) and have been making a simple 2d platformer to learn the basics. So far the collision detection (using only rectangles) is pretty much done and works on a basic "stop moving, adjust position" function being called by the player character, but the problem I'm having is that it's a little too precise - if two squares are stacked one on top of the other, rather than the player hitting the upper square and sliding to the floor it will snag on the top of the lower square.

Obviously this could be avoided by just making the two squares one rectangle, but I'd like to be able to build levels out of many small squares (plus the fact I can't work it out has made me all the more determined). I've tried various different techniques, such as having a smaller collision rect, or unifying the rects of the two squares on the fly, but to no avail.

Provided that all made sense, would anyone be able to suggest a new approach I could try? It's pretty simple I know, and I could just rip someone else's engine out and use it, but I wouldn't learn much in the process.

Thanks,

Bruno