Sparky's collision
Here is snippet by Ruccus thanks to him. But alway's got a syntax error
I don't get it, the command is blue, so the syntax is ok?
at SC_SetupObject 2,0,0
`Sliding Collision with Sparky's Collision dll
`By RUCCUS
`----------
`Email/MSN: Ask-RUCCUS@hotmail.com
`Main Program Settings
SYNC ON
SYNC RATE 0
AUTOCAM OFF
`Make a simple matrix, purely visual, not needed.
MAKE MATRIX 1,1000,1000,10,10
POSITION MATRIX 1,-500,0,-500
`Make the user's object.
MAKE OBJECT CUBE 1,20
POSITION OBJECT 1,0,5,0
`Make a box object, replace this with your map.
MAKE OBJECT BOX 2,100,50,50
GHOST OBJECT ON 2
POSITION OBJECT 2,0,25,60
`Setup object 2, the map, to be in group 0, and to be set to collision
`type 0 - "Polygon".
SC_SetupObject 2,0,0
`Position/orient the camera.
POSITION CAMERA 0,100,-300
POINT CAMERA 0,0,0
`Start the main program loop.
DO
`Store the user's old position on the xyz axis
OX# = OBJECT POSITION X(1)
OY# = OBJECT POSITION Y(1)
OZ# = OBJECT POSITION Z(1)
`Handle the player movement/orientation
MOVE OBJECT 1,( UPKEY()-DOWNKEY() ) * .5
TURN OBJECT LEFT 1,( LEFTKEY()-RIGHTKEY() ) * .5
`Store the player's new position on the xyz axis, after they've moved.
X# = OBJECT POSITION X(1)
Y# = OBJECT POSITION Y(1)
Z# = OBJECT POSITION Z(1)
`Call the sliding collision function, filling in the necassary variables
SlidingCollision(OX#,OY#,OZ#,X#,Y#,Z#,10,1,2)
SYNC
LOOP
`Sliding Collision Function
FUNCTION SlidingCollision(X1#,Y1#,Z1#,X2#,Y2#,Z2#,Radius#,Dyn,Obj)
`X1#-Z1# : The starting XYZ position of the intersection ray
`X2#-Z2# : The ending XYZ position of the intersection ray
`Radius# : The radius of the sliding collision sphere, usually you'd set this
` to the player's object's z sixe divided by 2. Our cube is 20 units thick,
` so we use 10 in the example.
`Dyn : The player object
`Obj : The map object that we want the player object to slide on
`Call the sc_SphereSlide command, using our variables.
`This command will create a mathematical intersection "Ray",
`this basically means that it'll make a 3D line starting from X1#,Y1#,Z1#,
`and ending at X2#,Y2#,Z2#. It'll then check if any of the polygons on the
`map object are inbetween these 2 points, if there is then it'll return a 1,
`if not, it'll return 0.
`What Sparky has done for us however is added in a few handy functions
`that are carried out inside of the SphereSlide command. Basically,
`once it detects an intersection, it'll get the angle the intersection
`occured at and using trigonometry (sin, cos and tan), it'll determine
`the logical position for an object to be if it were to "slide" along
`the polygon it hit. To make the system even more accurate however,
`Sparky's dll goes one step further by doing another intersection check on the
`new mathematical coordinates it just obtained, and checks that there wont be
`a collision there either. `It'll keep doing this until it reaches it's max
`iteration or until it finds a free, empty 3d location where the player's object
`can go. All this for free, sheesh!
C = sc_SphereSlide(Obj,X1#,Y1#,Z1#,X2#,Y2#,Z2#,Radius#,0)
`Now, sparky's dll will return the 3d position it thinks you should position your
`player object at AS WELL. These positions are returned using the sc_getCollisionSlideXYZ()
`commands. Basicaly the next code checks if an intersection occured in the first place
` (if C > 0), and if one did, then it retrieves the new XYZ location that the player should be
`placed at, and then positions the player object there accordingly.
IF C > 0
cx# = sc_getCollisionSlideX()
cy# = sc_getCollisionSlideY()
cz# = sc_getCollisionSlideZ()
POSITION OBJECT Dyn, cx#, cy#, cz#
ENDIF
ENDFUNCTION
`This last bit is a requirement of Sparky's dll. Basically, DBP's commands are grouped into plugins themselves.
`Theres a plugin for Camera commands, a plugin for Object commands, a plugin for Network commands, etc.
`However DBP, at the time of writing, includes only the necassary plugins for the program to work. So if you dont use
`and 3D commands, it wont include any 3D plugins. Sparky's dll requires the memblock commands, we haven't used any
`memblock commands yet so DBP wont include the Memblock plugin, which means Sparky's dll will crash. To fix this, we
`just add a DELETE MEMBLOCK 1 command after the function. DBP will never read this code, and so it will never get
`executed, but it will make DBP include the Memblock plugin.
`If you've used a memblock command elsewhere in your project, then you wont need this.
DELETE MEMBLOCK 1
My actual color is Color object 1, RGB(128,2,3) but I would like it to be random.