pygame is
Python
Simple DirectMedia Layer
 
 
pygame.org is
Site Swing
Rect Collision Response

Rect Collision Response

pymike (pymike)

Tags:

Description

This is a simple demo on how to do side-based rectangle collision response. It's extremely simple, and not very hard to understand.

Concept

I'm putting this here since it's not in the download. Basically how it works is when you move a rect, you first move along the X axis, test for a collision, move out, then move along the Y axis, test for a collision, and move out. This prevents the infamous "corner-catching" bug, and lets you move smoothly along walls.

Links

Home Page: http://pymike.pynguins.com/?page=tutorials&id=1

Screenshot


click to view original size

Pygame.org account Comments

If you wish to leave a comment with your pygame.org account, please sign in first.

March 5, 2010 11:33am - An Ony Mouse - nickname: (anonymouse)
flimm, the response is the actual stopping of the object. If you want you can extend it yourself to include bouncing :P

soggywaffles: same here! Now I can continue my game project!
January 26, 2010 3:48pm - Flimm - nickname: (flimm) - 2/5
It's got collision detection, but not response (bouncing off the walls and spinning).
March 18, 2009 10:24pm - pymike - nickname: (pymike)
Glad it helped. :-)
March 18, 2009 7:48pm - Ben - nickname: (soggywaffles) - 5/5
Just when I had lost hope.. Thanks. This has helped me out a lot.
spotlight

 
our projects
pygame.org welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
 
recent releases
Feb 12, 2012

Feb 11, 2012


Feb 10, 2012


Feb 9, 2012


Feb 7, 2012

Feb 5, 2012


Feb 4, 2012

Feb 3, 2012

... more!
 
for pygame related questions, comments, and suggestions, please see help (lists, irc)