CodeBase - complete sliding collision system using Sparky's
Return to the CodeBase listing
Category: Collision
Version: 1.0
Information
Uploaded: 8th Jan 2006 20:15
Modified: 1st Jan 1970 01:00
Author: Milkman
Summary
This is my sliding collision system that using sparky's dll to handle all collision.
Full Description
let me give a short explaination of what you need to do to get my system working.<br /> <br /> first, load your level as a normal object. then, set it up with sparky's by using then command:<br /> <br /> setupterraincollision object,group,freeobject<br /> <br /> the object is the object number of your level, the group you can leave as 0, and the free object is just any object not currently in use.<br /> <br /> ok, so you've got your level set up, so lets make an object to collide with that level and set up collision for it.<br /> <br /> make object cube cubeobject,size<br /> setupcollision(cubeobject,45,size/2,16)<br /> setcollisionon(cubeobject)<br /> <br /> that's all you need to set up collision on a cube. cubeobject is the object number of your cube, size is the size of the cube, obviously.<br /> there are 4 parameters for the setupcollision() function. the first is the object number to set up collision with, so we will put cubeobject. the second is the steepest climbable slope, which we will set as 45. this means that we can climb up any slope less than 45 degrees, but any slope steeper than that will cause us to slide down it, and is unclimbable. the third parameter is the radius of collision for the object. we will set that to half the size of the cube. the fourth and final parameter to set up collision is the number of sliding collision checks. 16 works fine for the test level i've provided, but depending on level geometry you may want to adjust this. the higher the number checks, the more accurate the collision, but also the slower.<br /> <br /> so once youve set up your level and object to collide with it, you can enter the main loop. once in the main loop, you can move the object horizontally and vertically. after moving it horizontally, you will want to update the collision horizontally. this can be done like this:<br /> <br /> updatehorizontalcollision(object)<br /> <br /> this automatically repositions the object provided (if it was set up for collision) horizontally to avoid collision, sliding automatically.<br /> <br /> once you've moved horizontally, you will want to move vertically to apply gravity and such. do this, then update the vertical collision like so:<br /> <br /> updateverticalcollision(object)<br /> <br /> this will automatically reposition your object to keep it on top of the level and not let it fall through.<br /> <br /> with the combination of updating the vertical and horizontal collision, your object will automatically slide vertically and horizontally and reposition itself right where it needs to be.<br /> <br />
Comments
No comments yet.