Sunday, April 24, 2011

AARect/AARect sweeped collision test in Python

The Gamasutra article "Simple Intersection Tests For Games" contains an AARect/AARect sweeped collision test. Unfortunately, the presented implementation is incorrect: It always reports a collision when the relative velocitiy of the two rectangles is 0.

I tried to come up with a corrected version and it seems to work fine so far. My implementation and test application using Python/pygame can be found here.


The filled rectangles represent the start positions, the non-filled rectangles represent the destination positions. They can be dragged around the screen using the mouse.

The highlighted filled rectangles represent the positions at the time of collision.

0 comments: