Posted: 18th May 2003 21:32
[center]!SLIDING COLLISION FOR CLASSIC AND PROFESSIONAL![/center]

Hello guys, I decided to make life easy and make up a couple of functions for sliding collision. I always hear people asking for help with sliding collision, but I dont think that will be needed anymore.

Now there are two different snippets! One works in pro, and one works in classic. Cheers guys! Here is what I ran this on,,,

System Specs:
Pentium 3
512 Ram
GeForce 2

With a sync rate of 80 I was running at a solid 90 FPS in pro, and a solid 83 in classic

[center]Here is the collision code for PROFESSIONAL[/center]

+ Code Snippet
REM Example code
sync on
sync rate 80
hide mouse

make matrix 1,2000,2000,1,1

Make object Cube 1,40
Position object 1,250,0,250
Collbox(1)

Make object sphere 2,20
Position object 2,0,0,0
Collbox(2)

do

`Gotta move that dude
yrotate object 2, camera angle y()
if upkey() = 1 then move object 2,4
if downkey() = 1 then move object 2,-4
yrotate object 2,wrapvalue(object angle y(2)+90)
if leftkey() = 1 then move object 2,-4
if rightkey() = 1 then move object 2,+4

SlideColl(2)

posx#= Object Position X(2)
posy#= Object Position Y(2)
posz#= Object Position Z(2)
position camera posx#,posy#+20,posz#-40

sync
loop

`this is the function for the collision box
Function CollBox(ob#)
obsx#= Object Size X(ob#): Rem Find the object size X
obsy#= Object Size Y(ob#): Rem Find the object size Y
obsz#= Object Size Z(ob#): Rem Find the object size Z
Make object Collision Box ob#,0-(obsx#/2),0-(obsy#/2),0-(obsz#/2),(obsx#/2),(obsy#/2),(obsz#/2),0
endfunction

`Now that the collision box is made, the function can be put in the main loop
Function SlideColl(pn#) : Rem pn# is PLAYER NUMBER
obx#= Object position x(pn#) : Rem Get the objects X position
oby#= Object position y(pn#) : Rem Get the objects Y position
obz#= Object position z(pn#) : Rem Get the objects Z position
If object collision(pn#,0)>0 : Rem here you may put NOT any objects you dont want collision with
   dec obx#,get object collision x()
   dec oby#,get object collision y()
   dec obz#,get object collision z()
   position object pn#,obx#,oby#,obz#
endif
endfunction


Code should work as pasted in pro.

[center]Here is the code for classic[/center]

+ Code Snippet
REM Example code
sync on
sync rate 80
hide mouse

make matrix 1,2000,2000,1,1

Make object Cube 1,40
Position object 1,250,0,250
ob#=1
Collbox(ob#)

Make object sphere 2,20
Position object 2,0,0,0

ob#=2
Collbox(ob#)

do

`Gotta move that dude
yrotate object 2, camera angle y()
if upkey() = 1 then move object 2,4
if downkey() = 1 then move object 2,-4
yrotate object 2,wrapvalue(object angle y(2)+90)
if leftkey() = 1 then move object 2,-4
if rightkey() = 1 then move object 2,+4

SlideColl(ob#)

posx#= Object Position X(2)
posy#= Object Position Y(2)
posz#= Object Position Z(2)
position camera posx#,posy#+20,posz#-40

sync
loop

`this is the function for the collision box
Function CollBox(ob#)
obsx#= Object Size X(ob#): Rem Find the object size X
obsy#= Object Size Y(ob#): Rem Find the object size Y
obsz#= Object Size Z(ob#): Rem Find the object size Z
Make object Collision Box ob#,0-(obsx#/2),0-(obsy#/2),0-(obsz#/2),(obsx#/2),(obsy#/2),(obsz#/2),0
endfunction

`Now that the collision box is made, the function can be put in the main loop
Function SlideColl(pn#) : Rem pn# is PLAYER NUMBER
obx#= Object position x(pn#) : Rem Get the objects X position
oby#= Object position y(pn#) : Rem Get the objects Y position
obz#= Object position z(pn#) : Rem Get the objects Z position
If object collision(pn#,0)>0 : Rem here you may put NOT any objects you dont want collision with
   dec obx#,get object collision x()
   dec oby#,get object collision y()
   dec obz#,get object collision z()
   position object pn#,obx#,oby#,obz#
endif
endfunction


Both those you should be able to paste right in and have work.

Hope you people get some use out of this. This was just made in a few minutes, not a final version at all. Probably wont even keep it........ But anyways I hope you like it!

EDIT: The first time I pasted I messed up,,,,it doesnt work in the SOURCE box,,,Ill post again. The code in the code snippet part should work though,,works for me when I copy and paste.

RPGamer
Posted: 18th May 2003 21:37
Here it is in the SOURCE box for Professional Collsion.

Cheers

RPGamer
Posted: 18th May 2003 22:06
i hear it alot but what is sliding collision i know the built in collision i know maths but i don't know sliding collision does it effect the speed like the built in does
Posted: 18th May 2003 22:21
With built in collision, the object simply STOPS when it collides. With sliding collision, the object SLIDES along the other object. Put it this way, if you are walking horizontal to a wall, and your arm brushes up against it, do you stop or keep going?

This is the difference between built in and sliding collision. With built in, you STOP when your arm brushes the wall. With sliding collision, its more like real life, and you keep on going.

Test it out if you have pro patch 4 (I think its less accurate in the demo) If you have classic and you get the code working (its a function defining error) please post the source here! I would like as many people as possible to benefit from this snippet.

I would like to credit Phaelax for inspiring me here. I was at the dark basic codebase and saw his sliding collision. This is where I found out there was Object Size I used the movement from his source, but thats just because I was in a rush.

Cheers,
RPGamer

RPGamer
Posted: 18th May 2003 23:39
This is the Classic collision in the source box...

RPGamer
Posted: 19th May 2003 2:35
Hey rpg gamer

Do you know how to make sliding collision for a .3ds landscape? I am inputing what I think is sliding collision and I finally got dbenhanced to recognize that my player (currently a cylinder)
is colliding with it but I cant move the player all the sudden. I can send you the source with some media if youre interested, otherwise have a great day and thanx for this snippet

RossageSausage
Posted: 19th May 2003 3:26
For landscapes you need to 'drape' a matrix of the object. This is a great site for DB stuff, and this is the link for their DLL to drape your matrix over your .x or .3ds object....

+ Code Snippet
http://www.nuclearglory.com/developer/db/kdll.html


I hope that helps you out!

Cheers!

RPGamer
Posted: 19th May 2003 7:40
Thanx for the help RPG gamer.....is that dll for dbpro or can it be used with dbenhanced?? I have dbenhanced and soon plan on getting pro but until now my only toy is DBE

Thanx
RossageSausage
Posted: 19th May 2003 15:05
Can be used with everything I think. Made for classic (and enhanced) but it has been ported to pro. Check out their web forums for help

http://www.nuclearglory.com/developer/db/kdll.html

RPGamer
Posted: 20th May 2003 0:52
okay RPGamer the code work but could you go in to more detail to explain it (the classic version plz) thx
Posted: 20th May 2003 3:37
What part do you need explained.

RPGamer
Posted: 20th May 2003 3:44
Eh, Ill just explain it all. I usually like people to figure it out for themselves but I am in a gererous mood lately

[center]This is the explanation for CLASSIC code. Its basically the same for pro, only emmitting the CLASSIC parts.[/center]

+ Code Snippet
REM Example code

REM Turn on SYNC and hide the mouse
sync on
sync rate 80
hide mouse

REM Make a matrix. Not really needed unless you want to get ground height.
make matrix 1,2000,2000,1,1

Rem Make a dummy object for collision, and stick it out somewhere. The objects number needs to be saved in a variable in classic or else the function wont work. After that is done, use the function to make a collision box (collbox) and use the variable you stored the object number in.
Make object Cube 1,40
Position object 1,250,0,250
ob#=1
Collbox(ob#)

Rem Make a plyaer object for collision. The objects number needs to be saved in a variable in classic or else the function wont work. After that is done, use the function to make a collision box (collbox) and use the variable you stored the object number in.
Make object sphere 2,20
Position object 2,0,0,0
ob#=2
Collbox(ob#)

do

`This is just some really (really) basic code to move an object.
yrotate object 2, camera angle y()
if upkey() = 1 then move object 2,4
if downkey() = 1 then move object 2,-4
yrotate object 2,wrapvalue(object angle y(2)+90)
if leftkey() = 1 then move object 2,-4
if rightkey() = 1 then move object 2,+4

`Activate the command to turn on sliding collision. Remember, that last time you saved ob# it was 2, so just using ob# in the function call works. In classic the function call must be a variable here.
SlideColl(ob#)

Rem just get some object positions of the character, this is used during positioning the object.
posx#= Object Position X(2)
posy#= Object Position Y(2)
posz#= Object Position Z(2)

Rem here you have to position the camera using the variables you made in the previous step.
position camera posx#,posy#+20,posz#-40

sync
loop

`this is the function for the collision box. The first thing that is done is make variables that store the object size in them. In the defining of the function, you have to plug in a variable which is used in object size. Next, you make the collison box mathematically finding the corners of the object using object size variables.
Function CollBox(ob#)
obsx#= Object Size X(ob#): Rem Find the object size X
obsy#= Object Size Y(ob#): Rem Find the object size Y
obsz#= Object Size Z(ob#): Rem Find the object size Z
Make object Collision Box ob#,0-(obsx#/2),0-(obsy#/2),0-(obsz#/2),(obsx#/2),(obsy#/2),(obsz#/2),0
endfunction

`Now that the collision box is made, the function can be put in the main loop. this is very basic sliding collision.
Function SlideColl(pn#) : Rem pn# is PLAYER NUMBER
obx#= Object position x(pn#) : Rem Get the objects X position
oby#= Object position y(pn#) : Rem Get the objects Y position
obz#= Object position z(pn#) : Rem Get the objects Z position
If object collision(pn#,0)>0 : Rem here you may put NOT any objects you dont want collision with
   dec obx#,get object collision x()
   dec oby#,get object collision y()
   dec obz#,get object collision z()
   position object pn#,obx#,oby#,obz#
endif
endfunction


Hope that helps.... Im only explaining because I want the community to get better at coding, which I believe can be helped through example.

RPGamer
Posted: 21st May 2003 23:35
using the help files and your explaination i think i get i might use it as the character collision bu i will definaty use it for the camera collision
Posted: 21st May 2003 23:47
Hey, howz about collision for when your at an angle to a wall, and with any object rotation ? You'd probably want planes for that.
Posted: 21st May 2003 23:59
Hamish! You! Be quiet! I am making some amendments later (better camera and stuff, updating the function)

RPGamer
Posted: 22nd May 2003 0:23
OK
Posted: 25th Jun 2003 2:58
I love it!!!! Thanks RPGamer!!! This has fixed my problem!
Posted: 25th Jun 2003 4:33
this is obselete with patch 5 DBP users and some video cards around the geforce 2 just dont tolerate statics in classic.

Its not a total solution for all pc users.
Posted: 30th Jun 2003 17:11
Moderator. Here's you a question that I been thinking for a long time in this newest project of mine: I have car model, wich the 3d animator of the project sent to me and I'm trying to make it follow the ground. With "get ground height" command I got the car to stay ON the ground but how to make it xrotate like it would look like the car is traveling on the ground. Right now I'm working with matrix, but later with bsp or x file when the 3d animator manages to finish the track model. Can you help me?
Posted: 30th Jun 2003 17:14
Sorry... The question was for Rpgamer. Moderator... Damn I'm dumb