COLD
Polygonal Collision Detection System [DBP]
Download COLD v1 Below
http://www.ruccus.net/COLD.rar - 5.61 MB
http://www.ruccus.net/COLD.zip - 8.71 MB
I’ve been trying to come up with a way to achieve polygonal collision responses and the feel of sliding collision found in many professional games these days much like Kensupens or G-Man and Lost in Thought's Collision Systems. I wouldve just used theirs but I couldnt understand all of the code and I like making my own code from the ground up. Here's the specs so far:
COLD Features:
Polygonal Collision Detection
Customizable Collision Responses
Built-In Sliding and Sticky collision
Lag Reduction Process
Collision Support for .x and .dbo objects
Automatic Ramp and Hill collision handling
COLD Explanation/Syntax
LOAD_COLD
Use this command to load the collision limbs used for the COLD function. It will create 6 limbs to shoot intersection data back to you for polygonal collision data and vertex intersection.
Object = Object Number you wish to detect sliding collision for
X1, Y1, Z1, X2, Y2, Z2 = Radius of collision detection. Its recommended to set these to a bit more than your object's dimensions divided by two. They must all be positive, the function will work out witch onces to change into negatives.
SYNTAX
LOAD_COLD(Object, X1, Y1, Z1, X2, Y2, Z2)
UPDATE_COLD
This command will update the necassary variables COLD requires to function properly. Be sure to call this at the beginning of the loop.
SYNTAX
UPDATE_COLD(Object)
COLD
This command will return automatic sliding collision data for polygonal objects using the intersect object commands. This command is used in partnership with the LOAD_COLD Function.
Object = Object Number you wish to detect sliding collision for
First = Starting object number for the list of objects you wish to detect collision against
Last = Last object number for the list of objects to detect collision against
Speed = Speed you wish object to slide at
Response = How COLD will respond to collision.
0 = Customizable Collision
1 = Sliding Collision
2 = Sticking Collision
SYNTAX
COLD(Object, First, Last, Speed, Response)
How COLD works:
Basically the user has collision "paddles" or limbs in this case, 6 of them, positioned on each main face of the user. An intersection ray is sent from the limbs to the user to detect when two polygons of an object cross eachother. When the intersection occurs, since the limbs are positioned so close to the user, if the intersection is anything greater than 0 COLD handles appropriately.
I never could grasp how people got the newvalue commands to give sliding collision so this is my attempt at it, but incase anyone wants to edit the way the collision works out just set the response value to 0 and nothing will happen but the intersection will still be detected and recorded in variables.
So far I've tested the system against both .x and .dbo files, Im working on testing it with .3DS. The system seems to work fine for all of the maps I've created but please note:
!! NO OBJECTS CAN BE INTERSECTING EACH OTHER !!
When any objects are intersecting eachother (or "crossing") the system gets confused and moves the user wrongly. Its a bug that may be fixed in later versions of the code.
Customization Process:
If the COLD responses dont suit your needs then here's how you can customize it to fit what you want.
COLD fills several global variables with data about the collisions, here are the variables and what they mean:
COLDfront#
- The user is colliding with something infront of them
COLDback#
- The user is colliding with something behind of them
COLDleft#
- The user is colliding with something to the left of them
COLDright#
- The user is colliding with something to the right of them
COLDtop#
- The user is colliding with something above of them
COLDbottom#
- The user is colliding with something below of them
COLDobj#
- The current object being collided with
Applying COLD to your program
COLD is put neatly into easy-to-use functions so applying it is simple. Just follow these steps:
Step 1:
Include the COLD.dba source file in your project that contains the COLD collision code.
- Open up dbp and find your project
- Once your project is open, select the "File" button to the bottom right of the screen
- Select "Browse" from the top
- Locate the COLD.dba file and select it
Step 2:
Load COLD's limbs (outside of the loop)
LOAD_COLD(Object,X1#,Y1#,Z1#,X2#,Y2#,Z2#)
I recommend setting the X, Y and Z values to the user's X, Y and Z values divided by two. Experiment until the collision works best for your object. Make sure the x y and z values are all
positive, the system works out which ones to turn negative.
Step 3:
Update COLD's variables for later use (inside loop)
UPDATE_COLD(Object Number)
This function only has 3 variables in it right now but as time progresses it will contain more
Step 4:
Call the main COLD command (inside loop at end)
COLD(Object, First, Last, Speed#, Response#)
And thats it! COLD should now be set up and able to be run with the simple function calls.
Future plans for COLD:
- Changing the limbs from cubes to small plains (for some reason I cant get this o.O even when I use "make object plain" instead of cube )
- Adding Bouncing Collision (for games like pong or pin-ball)
C/C is encouraged. The more comments and critisizm I get the better I can fix the code to work for everyone. Also, you can post any customized collision responses you've made here and Ill add them to the main post as a resource for newcommers. Please report any bugs you find along with a screen shot if possible so I can best see what's happening. The code is pretty simple so many should be able to understand it and edit it to their needs.
NOTE: COLD currently only works for one object colliding with another, so right now its ideal for solo games where youre just paying attention to your character colliding with objects, Im working on making COLD work for multiple objects colliding.
Download COLD v1 Below
http://www.ruccus.net/COLD.rar - 5.61 MB
http://www.ruccus.net/COLD.zip - 8.71 MB
Hope it helps!
-
RUCCUS
Current Projects: SHADE - Game Maker | Mecho - TGC Puzzle Entry | Halo Physics Engine | COLD - Polygonal Collision Detection