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 system

Author
Message
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 8th Jan 2006 10:42 Edited at: 2nd Mar 2006 18:24
I spent the time to create a collision system for use with my project, so i figured that i would let anyone else interested in it have access to it. i made it very simple to use, and its fairly fast because it uses sparky's dll.

im not going to explain it all, but basically you just call the setupcollisionsystem() function to set up the system, then call the setupcollision() function with your parameters to set up an object for collision. the updatehorizontalcollision() and updateverticalcollision() functions update the object for collision after movent.

i've attached the whole project in rar format, so you can compile it yourself. all the collision functions are in collision.dba

its pretty simple to understand, just look at the demo! one more thing is that you must have sparky's dll installed for it to work. i've put sparky's in with the project for you

good luck, and please post feedback!


EDIT:

Newest version:
http://forum.thegamecreators.com/xt/xt_apollo_download.php?i=753306

Functions available:


formerly xMik
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 8th Jan 2006 18:45
*bump*

come on, give it a try...

"Genius is 1% inspiration and 99% perspiration"
Bob Joe Sam Tom
20
Years of Service
User Offline
Joined: 28th Aug 2005
Location:
Posted: 8th Jan 2006 20:34
Wow... so little code...

*downloads*

Oh I get it now!

Those are functions you wrote. So basically, we just drop your "collision.dba" into our project, and use those functions with our values? I see.

BTW:

How do you "include" other source files into your main file?
The Lone Programmer
23
Years of Service
User Offline
Joined: 29th Jan 2003
Location: California, USA
Posted: 8th Jan 2006 22:47
This is rather newbish but where do I download the Sparky DLL from?

"Is The Juice Worth The Squeeze"
-The Girl Next Door
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 9th Jan 2006 00:44
@bob joe sam tom
yes, and just go to the project manager toolbar on the right in dbpro and click "add" under the source files section to add it.

@the lone programmer
ive included it in with the collision demo for you

"Genius is 1% inspiration and 99% perspiration"
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 9th Jan 2006 01:36 Edited at: 24th Jan 2006 21:02
let me give a short explaination of what you need to do to get my system working.

first, load your level as a normal object. then, set it up with sparky's by using then command:

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.

next, you need to turn the collision sytem on:


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.

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.
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.

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:

this automatically repositions the object provided (if it was set up for collision) horizontally to avoid collision, sliding automatically.

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:

this will automatically reposition your object to keep it on top of the level and not let it fall through.

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.

i hope this helps

EDIT:
not so short i guess...

"Genius is 1% inspiration and 99% perspiration"
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 9th Jan 2006 22:30 Edited at: 24th Jan 2006 21:05
here is an explaination of the three commands that return a result:


getverticalstate() returns a 1 if the object is hitting the ground, and -1 if the object is hitting the ceiling, otherwise zero. this is very useful for modefying gravity.

getverticalobject() returns the current object you are walking on (or hitting the ceiling of), which can be very useful for playing different footsteps depending on what you are walking on.

getverticalslope() returns the slope in degrees of the object you are walking on, where you are currently walking on it.

good luck

"Genius is 1% inspiration and 99% perspiration"
Bob Joe Sam Tom
20
Years of Service
User Offline
Joined: 28th Aug 2005
Location:
Posted: 16th Jan 2006 05:30
Wow, it's totally amazing-fabulicios. Can't wait to give it a shot with some of my maps.

I am the Placebo
www.placebosw.com
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 16th Jan 2006 06:03
thanks for the input

"Genius is 1% inspiration and 99% perspiration"
Bob Joe Sam Tom
20
Years of Service
User Offline
Joined: 28th Aug 2005
Location:
Posted: 16th Jan 2006 06:17
Problem:

When I compile, I get the "This Program has made an illegal error... blah blah blah blah", so I clicked close and another identical error pops up. But then the build goes ahead anyway, the program (game) launches and all I get is a black screen, and that exits after a couple of seconds. I've installed "collision.dll" and I have included xMik's "collision.dba" in my project.

Here's my code:



Here's the MS error details:

Quote: "DBPCOMPILER caused an invalid page fault in
module <unknown> at 0000:00000015.
Registers:
EAX=00000070 CS=016f EIP=00000015 EFLGS=00010206
EBX=0000ffff SS=0177 ESP=006af55c EBP=006af570
ECX=00000000 DS=0177 ESI=00000001 FS=10ff
EDX=00000000 ES=0177 EDI=00000000 GS=0000
Bytes at CS:EIP:
ff 00 f0 cc 93 00 f0 d0 9b 00 f0 00 00 00 c9 28
Stack dump:
006af560 00000177 67f14657 00000003 00000001 006af590 67f14712 00000001 0000ffff 008b150c 008b150c 67f1c370 67f1c370 006af5a0 67f14867 008b12f0 "


Thanks!

I am the Placebo
www.placebosw.com
Mattman
23
Years of Service
User Offline
Joined: 5th Jun 2003
Location: East Lansing
Posted: 16th Jan 2006 06:21
You can only use this for collision with a level made from a single object?

Why make sense when you could make brownies?
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 16th Jan 2006 06:33 Edited at: 16th Jan 2006 06:36
first of all, Bob Joe Sam Tom:

this will not work simply because the 'setupterraincollision' command needs a free object as the last parameter to work correctly. you supplied it with 0, which is not a valid object. try this:

if that doesn't work, then try setting up your level as a complex object, instead of as a terrain. do this like so:

other than that, your code is fine.
just to be sure, what is your version of dbpro?


@Mattman:
Quote: "
You can only use this for collision with a level made from a single object?
"

no. if you set up multiple objects with sparky's collision, my system will work with them all.

"Genius is 1% inspiration and 99% perspiration"
Bob Joe Sam Tom
20
Years of Service
User Offline
Joined: 28th Aug 2005
Location:
Posted: 16th Jan 2006 15:41
Oh thanks for the suggestions, I'll try em out today.

I have absolutely no idea what versionn my DBP is, how can I check? The about screen always says something like 1.3, but I only got DBP this august.

Hey... I just read on the back of the box that Dark Basic Pro has a .x to .bsp compiler... where is it???

I am the Placebo
www.placebosw.com
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 16th Jan 2006 17:44
if you haven't updated your dbp, chances are your version is behind. i would suggest going here:
http://darkbasicpro.thegamecreators.com/?f=upgrade_5_8
and getting the v5.8 update. as for the bsp convertor, it's located in the tools folder of your dbpro folder. i cant reccommend it though, as it cant convert much more than boxes and wedges. plus, dbp's bsp support is screwed up bad.

"Genius is 1% inspiration and 99% perspiration"
coolgames
20
Years of Service
User Offline
Joined: 26th Sep 2005
Location: Oregon, USA
Posted: 16th Jan 2006 17:55
Can you upload in zip format? I can't open .rar files.
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 16th Jan 2006 17:59
sure... here you go

"Genius is 1% inspiration and 99% perspiration"
Bob Joe Sam Tom
20
Years of Service
User Offline
Joined: 28th Aug 2005
Location:
Posted: 17th Jan 2006 03:25
OK, tried it with the complex command instead of the terrain one.

I still get the illegal errors, but the level loads now. But no collision. I tried doubling the size of the cube, but no luck.

I just think that sparky's dll doesn't work.

Help?

PS: Here is my new code:


I am the Placebo
www.placebosw.com
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 17th Jan 2006 03:46
aha!

this means the cube would move forward 5 every loop, but your radius is set to 2:

unfortunately, if you move your object horizontally more than the radius every loop, my collision won't work

try this:

that should work.

"Genius is 1% inspiration and 99% perspiration"
Bob Joe Sam Tom
20
Years of Service
User Offline
Joined: 28th Aug 2005
Location:
Posted: 17th Jan 2006 04:12
Nope, sadly, it still doesn't work.

I am the Placebo
www.placebosw.com
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 17th Jan 2006 04:47
im vexed.
could you upload me a copy of your map, so i could test it myself and try to get it to work? and also, make sure to update your dbpro to version 5.8

"Genius is 1% inspiration and 99% perspiration"
Bob Joe Sam Tom
20
Years of Service
User Offline
Joined: 28th Aug 2005
Location:
Posted: 18th Jan 2006 00:32
I tried updating DBP, and i I still get the errors, and the collision still doesn't work.

I've attached my zipped project.

I am the Placebo
www.placebosw.com
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 18th Jan 2006 01:01 Edited at: 18th Jan 2006 01:26
whay hadn't i seen it before? your problem is simple:



first you move the camera, then move the object to the camera's position, then update the collision. if the object collides, it is repositioned, but the camera is not! therefore, the camera is not seeing any effects of the collision, and eventually the object would bypass the collision as well.

here is the updated code:


also, i think i might know why you get errors during compile time, and im working on it.

edit:
ok, i tweaked the collision a bit, and i might have fixed those nasty errors you've been getting, but i can't guarantee it. anyways, you need to add this:

at the beginning of your code. i've attached the new version.

"Genius is 1% inspiration and 99% perspiration"
Bob Joe Sam Tom
20
Years of Service
User Offline
Joined: 28th Aug 2005
Location:
Posted: 18th Jan 2006 01:39
HUZZAH! It's fixed!

Well, almost. The collision works fine, excep fot gravity. It doesn't have built in gravity does it? If not would a simple code that changed the player Y work?

I still get the errors when I compile, but only if I run the exe from the compiler. If I run it from widnows, no problems at all. I think it might be the dll not liking my windows 98 or something.

Thanks so much xmik! You are da bomb!

I am the Placebo
www.placebosw.com
Bob Joe Sam Tom
20
Years of Service
User Offline
Joined: 28th Aug 2005
Location:
Posted: 18th Jan 2006 01:47
Ok, new problem.

My program randomly "stops responding".

DBP has never done this before, even on programs with much more complicated graphics...

Is my 350mhz pII with 128megs of ram and a Matrox g400 16meg card to feable for sparky's collision?

I am the Placebo
www.placebosw.com
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 18th Jan 2006 02:15
Quote: "It doesn't have built in gravity does it? If not would a simple code that changed the player Y work?"

yes, if you change the player y position in any way then updateverticalcollision(), that will work.

as for your random errors, i would need to know more. i highly doubt that sparky's collision is the problem. make sure your direct x is updated, and try to see if you can update your graphics card drivers, just for the heck of it.

"Genius is 1% inspiration and 99% perspiration"
FoxBlitzz
22
Years of Service
User Offline
Joined: 19th Nov 2003
Location: United States
Posted: 18th Jan 2006 02:16
Heh, those are some pretty low specs there, no offense. I'm a bit surprised that your computer even runs DBPro.

AMD Athlon 64 X2 4200+
1GB DDR-SDRAM (May increase to 2GB one day)
512MB ATI Radeon X1800 Series - Finally! A card that does pixel shaders correctly!
Bob Joe Sam Tom
20
Years of Service
User Offline
Joined: 28th Aug 2005
Location:
Posted: 18th Jan 2006 02:59
lol, actually, it runs most things surprisingly well, admitedly, I'm limited in the detail my levels can be, for development purposes. But hey, i'm a mac person. and i'm not gonna shell ou 900+ bucks for a reasonable PC.

But now that the Intel Based Macs are commin' out...

Oh yeah, windows and mac on the same machine.

I am the Placebo
www.placebosw.com
Shadowed Lightning
21
Years of Service
User Offline
Joined: 10th Nov 2004
Location:
Posted: 20th Jan 2006 19:47
Hi, before I try this, I have a question or two, I've never used objects before for my terrains, I use heightmaps and matrices, but I dont like the limitations of them because they look really bad, so I want to try this with objects. I make my terrains in Geoscape 3d, and export as .x, will that work? and which version of ur code should i download, the latest one?

AMD Athlon 64 3200 - GeForce 6800 GT - 320GB Hard Drive
1024MB RAM
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 20th Jan 2006 23:50
yes, any .x objects loaded into dbpro will work with this. i've uploaded the newest version with a demo, and here's a link, too
http://mike.getmyip.com/unleashed/collision.rar

"Genius is 1% inspiration and 99% perspiration"
Shadowed Lightning
21
Years of Service
User Offline
Joined: 10th Nov 2004
Location:
Posted: 21st Jan 2006 00:41 Edited at: 21st Jan 2006 00:52
Hey, xMik, I upgraded to version 5.8, and I have the .dll and everything, and I have been trying to get it to work, I run the program, (compile), and the screen goes blank, then the program ends, so to make sure it wasn't my coding, I downloaded a code you posted that you said worked, and it did the exact same thing, so about halfway through the loop, I made a huge error and typed a bunch of random gibberish, and ran the program again, it still appeared to run for a second and blank out, so I came to the conclusion it was never getting to the main loop, so I took all your commands and the sparky commands, and then it worked, I mean there was no collision, but something with either sparky's commands or your commands is screwing up the whole compile program, I tried it with your map and with my own maps and that didn't change the outcome either, any suggestions?
I'm downloading the new stuff right now, so I will try that too...
Really nice code by the way, I've been trying to accomplish somehting along those lines, just without as broad of a reach, and I never got past the intersect commands... Good work

PS: I don't have winRar, and I really wish I could find where to get it, but I can't find it anywhere on the net, and I've searched google many a times. So, could you please reload that with winZip, or point me out to winRar?

AMD Athlon 64 3200 - GeForce 6800 GT - 320GB Hard Drive
1024MB RAM
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 21st Jan 2006 04:48 Edited at: 21st Jan 2006 04:49
yes try the newest version that i posted, it should work fine... it compiles fine for me with v5.8

i aknowledge that the older versions did have an array problem that could mess things up, but it should be fixed with the newest version.

anyways,

winrar:
http://rarlab.com/rar/wrar351.exe

"Genius is 1% inspiration and 99% perspiration"
Stick of Doom
20
Years of Service
User Offline
Joined: 22nd Nov 2005
Location:
Posted: 24th Jan 2006 19:40
Hey xMilk, whenever i run my progam i get a "Runtime Error 118 - Array does not exist or array subscript out of bounds at line 347.", so i ran it through step-through mode and found that it dosen't like the "setupcollision" command, specifically the:

collision(number).ox=object position x(object)
collision(number).oy=object position y(object)
collision(number).oz=object position z(object)

part. I downloaded the newest version, but it didn't help. Could it be that i just coppied and pasted commands used in the demo with my own media? Or is it something else...
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 24th Jan 2006 20:43 Edited at: 24th Jan 2006 21:08
i think the problem is that the array is never created. since you have the newest version, be sure to add the setupcollisionsystem() function call at the top of your program. that creates the collision array. if you were using the older version, the problem could could be for a different reason, but it is fixed in the newest version.

basically, if you have version 5.8 of dbp, have the NEWEST copy of the collision functions, and did put setupcollisionsystem() at the top of your program, everything should work. different media would not cause you to have problems.

hope that helps

if all else fails, please post your code here so i can figure it out!

"Genius is 1% inspiration and 99% perspiration"
Stick of Doom
20
Years of Service
User Offline
Joined: 22nd Nov 2005
Location:
Posted: 25th Jan 2006 18:59
hmmm.... how could i have forgotten that.... but anyway, now it recgonises the command , but now my "player" object won't move . its like the level object is using box collision instead of polygon . i am using the "setupcomplexobject" command because the "setupterraincollision" is having some "issues", so to speak. Is that the problem? also, the exampe that came in the download is having some problems, so im sorry if i as too many questions here because i cant study that.
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 25th Jan 2006 21:09
Quote: "im sorry if i as too many questions here because i cant study that."


it's never too many questions

once again, do you have v5.8 of dbpro, and could you post your code here, please? i'm determined to get this working for you. i said it would work and that it's easy to use, so im going to stick to my promises.

"Genius is 1% inspiration and 99% perspiration"
Stick of Doom
20
Years of Service
User Offline
Joined: 22nd Nov 2005
Location:
Posted: 25th Jan 2006 23:24
well..... ok.... but im kinda a messy coder..... so dont expect to understand it all..... ive attached the media files as well as the code so it will run and not get a "file does not exist" error. as i said, im not very neat......
The Lone Programmer
23
Years of Service
User Offline
Joined: 29th Jan 2003
Location: California, USA
Posted: 25th Jan 2006 23:50
Say my object is more tall than wide. How would I set up collision so that the bottom of my object touches the ground and the sides of my object touch the walls when touching?

Like say I have a human character. I want him to be standing on the ground but when he walks up to the wall he doesn't have a huge gap.

In your collision function it looks like you made a one size radius. I am not sure whether that radius is the width or height. Maybe you could update your code and make separate values for the objects that aren't the same size all the way around?


Thanks,
The Lone Programmer

"Is The Juice Worth The Squeeze"
-The Girl Next Door
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 26th Jan 2006 00:13 Edited at: 26th Jan 2006 00:32
@Stick of Doom

problem solved
the fix?

instead of


set up all future objects with the setupcomplexobject command.
collision does work now, but for some odd reason, the collision for your map seems to be shifted over slightly this has something to do with your level and sparky's collision, my collision functions would have no effect on this.

anyways, hope i helped

"Genius is 1% inspiration and 99% perspiration"
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 26th Jan 2006 00:25 Edited at: 26th Jan 2006 00:27
@The Lone Programmer

this is actually very easy to do with the system's current state, but as a result you will be able to climb very steep slopes

simply adjust the slope value when setting up your player. try:


this will give your player a height of about twice the width, but as a result you will be able to climb a slope of up to 63 degrees.

because you brought this up, i might actually consider making an updated version of my code with support for height adjustment, while keeping the same slope functionality that's a big IF though, considering how busy i am with my current project, not to mention school.

hope this helped you out

"Genius is 1% inspiration and 99% perspiration"
Stick of Doom
20
Years of Service
User Offline
Joined: 22nd Nov 2005
Location:
Posted: 26th Jan 2006 00:26
umm... was the "problem solved" for my problem? if so.... could you attach the fixed code? because i changed it, but it still wouldnt let me move.......
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 26th Jan 2006 00:30 Edited at: 26th Jan 2006 00:33
oh stupid me... forgot to attached the updated code
the reason you can't move btw is because you had some non-collision-related movement problems, which i fixed just to demonstrate the collision to you. attached is the fix.

"Genius is 1% inspiration and 99% perspiration"
Stick of Doom
20
Years of Service
User Offline
Joined: 22nd Nov 2005
Location:
Posted: 26th Jan 2006 00:34
umm... was the \"problem solved\" for my problem? if so.... could you attach the fixed code? because i changed it, but it still wouldnt let me move........
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 26th Jan 2006 00:38
ahem
read the post above your post

"Genius is 1% inspiration and 99% perspiration"
Stick of Doom
20
Years of Service
User Offline
Joined: 22nd Nov 2005
Location:
Posted: 26th Jan 2006 14:07
oops, musta re-sent the post twice accidentally...
Stick of Doom
20
Years of Service
User Offline
Joined: 22nd Nov 2005
Location:
Posted: 26th Jan 2006 14:22 Edited at: 26th Jan 2006 14:23
hey, thanks for helping xMilk. my life has just gotten alot easier! now, just so i dont make the same mistake in the future, what was the non-collision-related movement problem?
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 26th Jan 2006 21:34
before, you were storing the camera position, repositioning the camera, positioning the object at the stored camera position, updating collision, and positioning the camera at the new object position.
this method is flawed because when you position the object, you are putting it to the old position, so no recent camera movement will affect it. then, you position the camera back at the object position, so your movement of the camera will be undone!

that's why you couldn't move

"Genius is 1% inspiration and 99% perspiration"
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 26th Jan 2006 23:40
bugfix!

while working with my collision system i recently found a bug that allowed you to 'stick' to walls if collision was updated in a certain order. this update fixes that problem. collision now works irregardless of the order you update it in. it's also slightly faster

collision.dba attached and code below



"Genius is 1% inspiration and 99% perspiration"
Stick of Doom
20
Years of Service
User Offline
Joined: 22nd Nov 2005
Location:
Posted: 27th Feb 2006 22:15
hmm.... nothing has happened on this thread for awhile.... so lets end that!

hey xMilk, is it possible to have one-way collision with an object? sorta like a one-way door or a platform in a 2d/3d scorllers (like in the "LTtypedemo" that comes with DBPro), where you can jump up through the platform, but not fall back down through it, and still have collision on the x-axis/z-axis?
Milkman
20
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 27th Feb 2006 22:41
that is possible, with a small tweak to the code. i've attached the tweaked version

formerly xMik
Stick of Doom
20
Years of Service
User Offline
Joined: 22nd Nov 2005
Location:
Posted: 27th Feb 2006 23:35
wow, thanks xMilk, it works perfectly!!

Login to post a reply

Server time is: 2026-06-09 15:42:54
Your offset time is: 2026-06-09 15:42:54