Thursday, October 23, 2008

Collision detection thoughts

So now that I have my method lovingly called "getTrianglesTransformedByCurrentOpenGLMatrix", which does seem to produce identical results with accelerated transforms, how do I use that for my collision detection? Well, for the needs of this game I would like to know if the spaceship is going to collide with the next obstacle or not. I would like to know that even before the collision happens, so that I can warn the user. Then when the obstacle is near enough and if the player has not adjusted their position, the ship should explode.

Before I was planning on doing this properly, to actually see if the polygonal objects intersect or not, but a friend convinced me otherwise. It won't matter as long as it works well enough so that the play experience isn't disturbed by it. So I will instead just have a two-dimensional collision volume for a ship. I will disregard the Z coordinate in the collision detection. I think I'll place this collision volume to the base of the ship, because that part is most visible to the player and any error there would be too glaring.

My obstacles are very low-poly, but I have some power-ups that may be smaller than the ship itself. If I do the detection by simple is-vertex-inside-any-triangle -tests, then I should probably subdivide the collision volume to have some extra vertices so that it doesn't happen that a power-up would just slide through it because no vertex in the ship happened to be inside any of the power-up's vertices.