Friday September 22, 2023
 home | about | contact | Donations

 3D File Formats The bits and bytes...

Quake 3 BSP [Collision Detection]
Author bkenwright@xbdev.net

We need some collision detection to stop us going through walls!  Collision detection and reaction is one of the main areas of any game.  As you have Rendering, AI, Physics and of course Collision Detection.  Using the BSP Map format, which uses planes, its can be found to be relatively efficient and simple to determine points of collision with our level.  As the level is all divided up into planes.  So a solid understanding of planes and how to work with them is needed.  It mostly comes down to the trusty plane equation and knowing if a ray/point is on one side of a plane, intersects a plane, what is the point on the plane etc.

So if your knowledge of planes and there workings is a bit rust, it might be worth while doing a bit of reading and experimenting with some demos.  I've added some test/debug code for displaying planes in the demo so it makes it easier to disect and learn what is happening with the code..

 Collision Detection (Line) Uses a start and end ray we can go through all or level planes and determine the point of collision of the wall.  Basically uses the same principle you use to determine the point where the player is for rendering, recursion through all the nodes.  The added testing is determining if our line crosses the plane and if so if its the plane where interested in. As if you run the demo or are familiar with bsp file formats, you'll be aware that there are numerous planes that make up a resulting node.  Through various testing we can determine the correct plane and project our collision point onto the plane. So we determine if there is a collision, Yes or No, and we can also find the point of collision, so we can use it.  For example if the user is walking around the layer firing his super nova lazer gun, we might want to see small sprite explosions when the weapon is fired at the wall.  Using our code we can determine if the shot hit the wall and its point of intersection so we can display the effect. Download Source Code (324kb)

 Visitor: Copyright (c) 2002-2023 xbdev.net - All rights reserved. Designated articles, tutorials and software are the property of their respective owners.