Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Sliding Collision Function/Commented Example - Sparky's Collision dll (V2)

Author
Message
RUCCUS
17
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 22nd Sep 2006 04:32 Edited at: 18th Mar 2007 23:59
Download Sparky's Collision Dll (V2) Here

(I posted this here as opposed to the Code Snippets board as it occurs to me newcommer's look here more than there, but MODs feel free to move it if you see fit)

Ever since DBP was created people have been having a lot of trouble with sliding collision, and there's been a lot of methods created to take care of it. Kensupen, G-Man and Lost In Thought made a sliding collision function using DBP-Native commands alone, there's Nuclear Glory, a collision dll thatll work wonders with DBP, but it costs money, and there's been some other math guru's that have made functions using the vertex manipulation commands and some nifty trig.

Sparky (now a MOD) has been kind enough to make a free plugin for DB/DBP, that provides a large amount of collision/ray intersection commands. They're faster than DBP's built in collision commands, have more functionality, and IIRC some of the commands are as fast/faster than NGC's commands. Dont quote me on that one though.

Anyways, the download comes with a huge amount of commented examples, but they might be a little too complex for a complete newcommer to grasp. So here's a simple code snippet for anyone to play with, it's fairly commented so I dont think it should be too hard to understand, and it has all of the collision stuff packaged into 1 function to make implementation fairly easy.



Im not saying I invented the method or anything, there's not much TO invent seeing as Sparky's dll comes with actual sliding collision commands, handling all of the hard stuff, I just think this is a little simpler for newcommer's to understand and get to grips with.

Goodluck,
- RUC'

PS: Ill try and throw together a flash tutorial on how ray casting works maybe tomorrow night, that should clear up quite a few other questions as well.

Darth Vader
17
Years of Service
User Offline
Joined: 10th May 2005
Location: Adelaide SA, I am the only DB user here!
Posted: 22nd Sep 2006 06:21
Did I prompt you?
Looks great will have a look at your snippet now!


Darth Vader
17
Years of Service
User Offline
Joined: 10th May 2005
Location: Adelaide SA, I am the only DB user here!
Posted: 22nd Sep 2006 08:40 Edited at: 22nd Sep 2006 11:45
Finally I got Sprakys collision DLL working! Thanks RUCCUS!
New game coming soon!


Dark Master
16
Years of Service
User Offline
Joined: 4th Apr 2006
Location:
Posted: 22nd Sep 2006 23:30
I ran your code and it looks like you have the same problem im having, in order to get the sliding collision you have to use a radius. so techically inside your box is a sphere, so the corners go into the clear box as it is colliding with it, or if instead of a cube you make a box.
make object box 1,20,20,40
then you will notice that the box will go into the clear box, and if you increase the sphere size to adjust for the rectangle shaped object then the side of it are unable to touch.
Thanks for commenting your code though it helped me understand things better.

RUCCUS
17
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 23rd Sep 2006 05:21
Dark thats true but there's work arounds for that, I wanted to make this as simple as possible. Yo can use eliptical collision or, if you're not shy of losing too much FPS, there are methods for getting perfect polygon-to-polygon collision working, though its terribly unrealistic (even the best selling games tend to use eliptical collision, it just works).

Your signature has been erased by a mod because it's larger than 600x120...
Dark Master
16
Years of Service
User Offline
Joined: 4th Apr 2006
Location:
Posted: 25th Sep 2006 05:37
I have been messing around with the collision but i cant find an eliptical collision, i have tried using the box collision but it still uses the sphere collision, when your trying to make the object slide down slopes.
Because the function requires a radius it acts like a sphere.
Could you please give an example of using the eliptical collision?

Heckno
18
Years of Service
User Offline
Joined: 8th Sep 2004
Location: Palm Coast, FL
Posted: 25th Sep 2006 22:33
TY ruccus, now I can stop modelling for a bit and work on my engine...
Zotoaster
17
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 25th Sep 2006 22:42
How can you stand all those capital letters?

RUCCUS
17
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 27th Sep 2006 14:46 Edited at: 28th Sep 2006 04:49
I cant help it, its how I learnt to program.

Anyways, here's an example that uses bouncing collision, pretty basic right now.



Your signature has been erased by a mod because it's larger than 600x120...
RUCCUS
17
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 28th Sep 2006 04:49 Edited at: 28th Sep 2006 04:55
Here's an example of showing some basic pool ball physics...



Your signature has been erased by a mod because it's larger than 600x120...
RUCCUS
17
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 29th Sep 2006 01:44
Pool Example



And here's a pool sim with media and balls getting pocketed. Its pretty well commented as well, Im thinking now that Ill write a tutorial on how to make a complete pool game from start to finish. "My First Pool Game" , eat your heart out Chris K. (Joking)

Here's the code;



In the attatched zip file is:

- DBP/DBA File
- Textures for every pool ball + Uv map if you want to change them
- Pool table and ball model
- Exe

Your signature has been erased by a mod because it's larger than 600x120...

Attachments

Login to view attachments
RUCCUS
17
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 11th Oct 2006 02:25
This not helping anyone?

Your signature has been erased by a mod because it's larger than 600x120...
dononeton
18
Years of Service
User Offline
Joined: 12th Jun 2004
Location: Tusaloosa, AL : USA
Posted: 15th Oct 2006 04:51
Yes! it has helped alot! Thank you
sadsack
19
Years of Service
User Offline
Joined: 27th Nov 2003
Location: here
Posted: 15th Oct 2006 05:11 Edited at: 15th Oct 2006 05:37
the link to the dll (v2) is down. Is there a nother place I can download it?
renny

Edit: It is working now. Thanks to the time out on the downloads I can't download the pool. People think every one have DSL. If I could get it I would have it, I live way out in the woods far from any city. So I must drive 20 miles tomorrow to a hot spot just to download it.
Guyon
19
Years of Service
User Offline
Joined: 6th Jun 2003
Location: United States
Posted: 15th Oct 2006 06:32
RUCCUS, or anyone.

Say you have an object like a long pencil shaped space ship and used elliptical collision. If my ship turns 90 degrees will my elliptical object turn too?

In other words can you rotate an elliptical object? If so can you post a simple exe running example?
RUCCUS
17
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 15th Oct 2006 09:53
Renny you could just use your own media and the code I supplied, would probably be faster. Replacing any pool balls with spheres, and then either modelling a quick pool table or using boxes with DBP code. Meh.

Guyon it depends on how your handling eliptical collision, I dont know what method you're using, but when it comes to programming, unless someone else supplied you with the code and you just pasted it in without understanding it, usually if you dont program it to do something, it wont.

Sparky's dll doesnt have an eliptical collision command does it?

Your signature has been erased by a mod because it's larger than 600x120...
Zotoaster
17
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 15th Oct 2006 14:00
Hey Ruc', You dont mind if I use a slightly twisted version of your function in my NVIDIA compo entry do you? That would b great. Thanks.

RUCCUS
17
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 15th Oct 2006 15:00
Nope .

Your signature has been erased by a mod because it's larger than 600x120...
Zotoaster
17
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 15th Oct 2006 15:04
You a life saver

Para _Charlie
16
Years of Service
User Offline
Joined: 31st May 2006
Location: Wisconsin
Posted: 15th Oct 2006 16:35
Awesome post. Made alot of things easier for me. Thanks for taking the time to post this, much appreciated.

DBP 6.2 DX 9.0c
3.2Gig Proc, 2Gigs Ram, SATA HD, Gigabyte MB, 6800GT Vid
StevetS
18
Years of Service
User Offline
Joined: 19th May 2004
Location:
Posted: 17th Oct 2006 16:03
Nice post mate, thanks for taking the time to help.

I'm looking forward to going through it when i get home from work tonight.

Cheers.

dononeton
18
Years of Service
User Offline
Joined: 12th Jun 2004
Location: Tusaloosa, AL : USA
Posted: 22nd Oct 2006 02:24
When I call
in my game loop could the last arg which is map be a variable. Meaning whatever level gets loaded then that level is = map and therefore have collision? Just tring to think of ways to type less code
dononeton
18
Years of Service
User Offline
Joined: 12th Jun 2004
Location: Tusaloosa, AL : USA
Posted: 22nd Oct 2006 21:25
Ok
as you can see I made an array to store the paths to the levels. I guess now I need to make a selection screen and use the if to select each index
Don Malone
19
Years of Service
User Offline
Joined: 27th Apr 2003
Location: Birmingham, Alabama
Posted: 3rd Nov 2006 02:52
Thanks RUCCUS.
It never hurts to have another example and especially one as well commented as this one.

In Memory of My Dad.
I miss you very much.
Lampton Worm
20
Years of Service
User Offline
Joined: 4th Sep 2002
Location: United Kingdom
Posted: 28th Dec 2006 01:42
Hi,

Using a slightly modified version of the code from the first post, and a test export box from CShop, I've somehow got a problem with sliding collision (basic) and I wondered if you could help.

Fire this up, and basically go towards the box and slide around it... for me, one side of the box is sticky, but the rest slide - any ideas?



The .X is also attached... any help greatfully appreciated.

Ps. code is just modified for mouse turn left/right and to load the .x model.

Cheers

Attachments

Login to view attachments
dononeton
18
Years of Service
User Offline
Joined: 12th Jun 2004
Location: Tusaloosa, AL : USA
Posted: 28th Dec 2006 02:26 Edited at: 28th Dec 2006 02:31

change the 0 at the end of your SC_SetupObject for your level to 2
not sur why that works
indi
20
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 28th Dec 2006 02:34
good work again RUCCUS, I linked it to your other collision posts.

Lampton Worm
20
Years of Service
User Offline
Joined: 4th Sep 2002
Location: United Kingdom
Posted: 28th Dec 2006 18:38
@dononeton, yup that sets it to use box collision, not polygon

The problem is that box is just a major cut down from the rest of the level model, which as a whole needs poly not box collision.

Thanks for trying though! Hmm, may need to dig out NGC after all.

Cheers
dononeton
18
Years of Service
User Offline
Joined: 12th Jun 2004
Location: Tusaloosa, AL : USA
Posted: 29th Dec 2006 03:20
Well I haved used More complex models with the collision set to polygons and it worked fine
RUCCUS
17
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 29th Dec 2006 03:42
Lampton, thats really weird, Ive never seen it happen before. I tried modelling my own box and positioning it in relatively the same place as yours, and the same thing happened. Im not sure if its something to do with the scale, Ill keep experimenting later to try and figure it out though.

Lost in Thought
18
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 29th Dec 2006 06:29
I thought this was fixed in the early betas I tested ages ago for v1. It's an offset error I think. The model is offset so when positioned at 0,0,0 the polys are 1500 units appx away and the far side is out of the bounds. Rotate the object 45 degrees on the y angle, use the update object command, and you'll see the sticky points should move. Position the object at -1000, 0, -1000 and it should work on all 4 sides no matter the rotation. Try to keep the mesh centering as close as possible as DBP isn't very friendly at retrieving some offset data. I'll try and run some tests later.

Kieran
16
Years of Service
User Offline
Joined: 6th Aug 2006
Location: Hamilton, New Zealand
Posted: 31st Dec 2006 00:07 Edited at: 31st Dec 2006 00:07
it worked on the example but when I put it into my game it did nothing



dononeton
18
Years of Service
User Offline
Joined: 12th Jun 2004
Location: Tusaloosa, AL : USA
Posted: 31st Dec 2006 00:14
dont you need to sync your game every loop?
Kieran
16
Years of Service
User Offline
Joined: 6th Aug 2006
Location: Hamilton, New Zealand
Posted: 31st Dec 2006 00:15
well thats a problem to start with lol

Kieran
16
Years of Service
User Offline
Joined: 6th Aug 2006
Location: Hamilton, New Zealand
Posted: 31st Dec 2006 00:25
nvm i solved it lol

Lampton Worm
20
Years of Service
User Offline
Joined: 4th Sep 2002
Location: United Kingdom
Posted: 31st Dec 2006 09:41 Edited at: 31st Dec 2006 09:41
Hi,

Thanks for looking into this guys. I think there is a command in Apex's CSM command set I'm using that does something to do with offsets/DBP, may be something there to help.

For now I've also added NGC support so I can flip between the two collision techs.

Cheers
RUCCUS
17
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 31st Dec 2006 14:32
I think I understand the problem a bit, but probably not. The thing is, if you've got a model like yours, where theres only media on one side of an axis, then the object size commands dont work at all. It looks like objects need to be centred for it to work at the moment. Thats not to say you could have other media on the other side of the axis to balance it out though.

Darth Vader
17
Years of Service
User Offline
Joined: 10th May 2005
Location: Adelaide SA, I am the only DB user here!
Posted: 5th Jan 2007 04:24 Edited at: 5th Jan 2007 04:28
Hey RUCCUS I was wondering.

I'm making a game and to keep things a little organised I am going to assign variables to objects in certain groups. For instance

Player and AI will be assigned to variables 1 to 100

Objects that the player or AI's can interact with or pick up will be assigned to 101 to 200

But for levels I am using that new program WORLD it's in the program annouments board. It's a great program it outputs everything into a .dbo file. I was wondering if it were possible to load the level and give it a single variable so then I could apply collision to it once. So all the object in the level (Buildings, trees, rocks, etc) would have collision after calling one fucntion instead of hundreds for all the different objects. Is it possible? I'm not sure how the program stores all the objects and if it stores them all in one file, but if it does could it be done?
Thanks!



[EDIT]I just read your collision resource post. You mentioned collision maps. How do you make these in regards to the map editor I mentioned above?[EDIT]

RUCCUS
17
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 5th Jan 2007 14:10
Ok, I hit back right before I clicked post so my anser disappeared, Ill sum it all up in short;

a) You dont need to use a bunch of sliding collision commands on a bunch of objects, because your entire world is one object exported from WORLD, as you said.

b) If you did have a time where you have a bunch of objects, you'd use sparky's grouping system and call the sliding collision commands on a group instead. Look above in my pool example to see how groups work.

c) Youd have to model the collision map yourself. Usually you load your actual map into a modelling application, and then model a simpler version of it overtop. Its good to remember that in some areas you shouldnt model anything, like for example if you had a huge tree, and you knew that the player cant get to the branches of the tree in the game, for the collision map, dont even bother modelling the branches, just model the trunk.

Darth Vader
17
Years of Service
User Offline
Joined: 10th May 2005
Location: Adelaide SA, I am the only DB user here!
Posted: 6th Jan 2007 12:12
Julius Caesar
16
Years of Service
User Offline
Joined: 14th Apr 2006
Location:
Posted: 17th Mar 2007 21:58
@RUCUS(or anyone else?!)...
How would I go about putting elliptical (or polygon) sliding collision into a game? Obviously using Sparky's dll...

I looked around and I thought I could just type in an ellypse's radius to the sphere's radius box. I just ended up with no collision whatsoever.

I had the radius as: (x^2)+(y^2)+(z^2)

What have I done wrong?

I came, I saw, I conquered. The die is cast. It is not these well-fed long haired men that I fear, but the pale and the hungry looking. Et tu, Brute?
-The Man Himself
sadsack
19
Years of Service
User Offline
Joined: 27th Nov 2003
Location: here
Posted: 17th Mar 2007 23:55
This does not work, no collision at all. What I did was just replace the objects with my objects. Now the one thing I did do is scale the tank. I know in NGC they have a scale comm. I could not find one in sparky dll. Does any one know why this has no collision?



Thank you
renny
dononeton
18
Years of Service
User Offline
Joined: 12th Jun 2004
Location: Tusaloosa, AL : USA
Posted: 18th Mar 2007 00:45
change this to this and see if it helps





AMD Athlon 64 x2 Dual Core Processor 3800+,MMX 3DNOW (2CPUs)
1024 MB RAM
GeForce 7300 GT 512 MB
sadsack
19
Years of Service
User Offline
Joined: 27th Nov 2003
Location: here
Posted: 18th Mar 2007 01:37
Ok I did that dononeton and my tank stops now. but it is half way in the wall. see photo:
code:


I found the scale comm.
thank you
renny

Attachments

Login to view attachments
RUCCUS
17
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 18th Mar 2007 02:54
You do realize you have to change the collision radius right?

sadsack
19
Years of Service
User Offline
Joined: 27th Nov 2003
Location: here
Posted: 18th Mar 2007 03:25
yes, but when I do my tank is setting 20 feet in the air. I tryed to use the box collision
load object "panther.x",1
scale object 1,2000,2000,2000
position object 1,0,50,0
sc_setupObject 1,0,2( where you make this a 2 not a zero)
SC_allowObjectScaling 1
SC_updateobject 1

could not make box collision work, or is there not box collision?
Thank you renny
RUCCUS
17
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 18th Mar 2007 03:39
Yes but, you're using a radius of 20, is you're tank 40x40x40? If its not around those dimensions, 20 is a bad radius to use. Box collision should work, ive used it before.

dononeton
18
Years of Service
User Offline
Joined: 12th Jun 2004
Location: Tusaloosa, AL : USA
Posted: 18th Mar 2007 04:08
so what you are saying is the collision now works but it is not colliding until about half way through the tank right? If I am understanding right the collision model that sparkys dll makes is in the center of your tank. Increase the radius in sc_SphereSlide function in your game loop

AMD Athlon 64 x2 Dual Core Processor 3800+,MMX 3DNOW (2CPUs)
1024 MB RAM
GeForce 7300 GT 512 MB
RUCCUS
17
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 18th Mar 2007 04:44
I...said that...

dononeton
18
Years of Service
User Offline
Joined: 12th Jun 2004
Location: Tusaloosa, AL : USA
Posted: 18th Mar 2007 16:07
yeah I know. Mabe He did not understand why

AMD Athlon 64 x2 Dual Core Processor 3800+,MMX 3DNOW (2CPUs)
1024 MB RAM
GeForce 7300 GT 512 MB

Login to post a reply

Server time is: 2022-12-01 09:37:07
Your offset time is: 2022-12-01 09:37:07