PDA

View Full Version : 2D Race Car collision detection



neonnds
6th July 2008, 09:10
Hi all. I am working on a 2d car racing game. My problem atm is collision detection. Currently I am using QtGui.QTransform to manipulate (translate and rotate) the race car (QGraphicsItem) around the track. When the car moves i check to see if a collision has occured, and if it has i do not paint the move to the screen, rather i revert the transformation and then paint the car to the screen. So in essence i am reverting back to the last known safe transformation of the car. This also gives the user the illusion that the car has not moved, if for example, they are trying to drive it through a wall.

My problem is that the change from a move that resulted in a collision back to the last save transformation is laggy. Also the actual collision detection is not as accurate (detects a collision even though the car shape() is not in direct contact with the track shape() ).

Check out my code, do a few laps, and if you can think of any improvements to my aforementioned problems i will be more then happy listen :)

I am using PyQt (Python + Qt4.4).

Source Code:
http://www.iodump.com/

Cheers.