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.

Code Snippets / [DBP] BSP style sliding collision with only a .X model

Author
Message
gbuilder2
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: New Zealand
Posted: 21st Aug 2003 11:31
Kensupen,
Have you tried this .X collision Code with Upgrade5? It doesn't seem to like it..

gbuilder.

Life is a Game.
Kensupen
21
Years of Service
User Offline
Joined: 19th Sep 2002
Location: United States
Posted: 21st Aug 2003 23:43
Yeah, I noticed this as well. Someone found out what the problem is. In v4.1 and prior, intersect object was buggy and would check to infinity no matter what number was set in it. The new version in U5 works as it is supposed to. All you have to change is the distance in the intersect object lines and it works again. I think I have them set to 1. Try setting them to 100 or so.

-Kensupen

Nerdsoft Creations - Lead Programmer
System Specs: AMD XP 1700+, WinXP Home, 1GB PC133 ram and Radeon 9500 using DX9
gbuilder
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: New Zealand
Posted: 22nd Aug 2003 08:27
No,I can't get it to work,
Is this the general area...

-------------------------------------------------
`They return the distance when they hit an object
for x=0 to checks-1
chx#=newxvalue(cx#,x*angwidth,1)
chz#=newzvalue(cz#,x*angwidth,1)
ang#(x,1)=intersect object(1,cx#,cy#,cz#,chx#,cy#,chz#)
if ang#(x,1)=1 then ang#(x,1)=999999
ang#(x,2)=x*angwidth
sort#(x,1)=ang#(x,1)
sort#(x,2)=ang#(x,2)
next x
-------------------------------------------------
Perhaps someone who has got this '.X collision code' working with upgrade5 could kindly post it for the mathematically-challenged like myself.

gbuilder.

AMD900mhz, 256mb Ram, 64mb GForce2 MX400 Graphics card, Windows ME.
gbuilder
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: New Zealand
Posted: 22nd Aug 2003 12:42
Hold that request
Got it, change these two lines..

--------------------------------------
chx#=newxvalue(cx#,x*angwidth,100)
chz#=newzvalue(cz#,x*angwidth,100)
--------------------------------------

gbuilder.

AMD900mhz, 256mb Ram, 64mb GForce2 MX400 Graphics card, Windows ME.
Kensupen
21
Years of Service
User Offline
Joined: 19th Sep 2002
Location: United States
Posted: 22nd Aug 2003 12:44
It's simple.
Just change these 2 lines:
chx#=newxvalue(cx#,x*angwidth,1)
chz#=newzvalue(cz#,x*angwidth,1)

to this:
chx#=newxvalue(cx#,x*angwidth,100)
chz#=newzvalue(cz#,x*angwidth,100)

Re-compile, and voila! Fixed.

-Kensupen

Nerdsoft Creations - Lead Programmer
System Specs: AMD XP 1700+, WinXP Home, 1GB PC133 ram and Radeon 9500 using DX9
Kensupen
21
Years of Service
User Offline
Joined: 19th Sep 2002
Location: United States
Posted: 22nd Aug 2003 12:45
Darn, you beat me to it while I was typing...

-Kensupen

Nerdsoft Creations - Lead Programmer
System Specs: AMD XP 1700+, WinXP Home, 1GB PC133 ram and Radeon 9500 using DX9
HartZa
20
Years of Service
User Offline
Joined: 5th Jun 2003
Location:
Posted: 2nd Sep 2003 20:08
VERY GOOD!!!!!
The best collision code i've ever seen, totally!
I've been working with same style code for days, and haven't found any good solutions...
Without pressing enter, it was about 60fps, but after pressing enter, i got 400-450fps.

Stats: Athlon XP Palomino 2600+ 2088mhz, GF4Ti420 128mb AGP8x, 512mb ddr dual-memory
Terabyte
21
Years of Service
User Offline
Joined: 28th Dec 2002
Location: UK
Posted: 3rd Sep 2003 15:35
hi

er......

dont know if those last 2 posts are going to answer this question but im on patch5. The executable you provide works fine but the source code you have given doesnt work.

The executable gives perfect collision
The source code untouched when compiled allows me to walk straight through walls.

>>TerraByte. Putting the Byte back into Terragramming<< If my post has less than 20 typos then it wasnt me who wrote it!
Chenak
21
Years of Service
User Offline
Joined: 13th Sep 2002
Location: United Kingdom
Posted: 3rd Sep 2003 18:59
lol,Read the above posts

change:

chx#=newxvalue(cx#,x*angwidth,1)
chz#=newzvalue(cz#,x*angwidth,1)

to:

chx#=newxvalue(cx#,x*angwidth,100)
chz#=newzvalue(cz#,x*angwidth,100)

Once you start down the Dark Path, forever will it dominate your destiny...
Terabyte
21
Years of Service
User Offline
Joined: 28th Dec 2002
Location: UK
Posted: 4th Sep 2003 02:37
hmm i had a feeling they were relevant

If i wanted more than one object to be detected for collision what would i do. i.e. if my world wasnt made up of one object and it was made up of several or if i made a world and had extra objects put in like er.. desks or chairs.. or some other object. could i detect for colision with these objects...

>>TerraByte. Putting the Byte back into Terragramming<< If my post has less than 20 typos then it wasnt me who wrote it!
Chenak
21
Years of Service
User Offline
Joined: 13th Sep 2002
Location: United Kingdom
Posted: 4th Sep 2003 03:52 Edited at: 4th Sep 2003 03:53
change the intersect object to a variable such as:

intersect object(1,cx#,cy#,cz#,chx#,cy#,chz#)

to:

intersect object(obj,cx#,cy#,cz#,chx#,cy#,chz#)


There should only be two of these, one in the _collision sub routine and one in the _ramp sub routine.

Then before the routine is called, set the variable number like this:



At the moment, im trying to figure out how to make multiple objects and a camera can all use the collision but it just aint working for me Anyone know how to do this?

Once you start down the Dark Path, forever will it dominate your destiny...
Kensupen
21
Years of Service
User Offline
Joined: 19th Sep 2002
Location: United States
Posted: 6th Sep 2003 00:09
What you have to do is use the collision check function for each object and the camera. It will slow down the more times it's called, but that is the only way this code works. Once CShop gets a little more stable, I was going to make a Quake rip-off game using my collision as a tech demo. I'm still waiting to get bored enough to start it.

-Kensupen

Nerdsoft Creations - Lead Programmer
System Specs: AMD XP 1700+, WinXP Home, 1GB PC133 ram and Radeon 9500 using DX9
Lukeyboy
20
Years of Service
User Offline
Joined: 5th Sep 2003
Location:
Posted: 6th Sep 2003 03:46
Great stuff! Thanks for sharing.
Terabyte
21
Years of Service
User Offline
Joined: 28th Dec 2002
Location: UK
Posted: 23rd Sep 2003 20:52
so er....
seems there are alot of modifications to this code.
Could sombody please post the final version of this code cheers.

Or...
Post the original and list all the fixes.. i just dont want to miss one thx

>>TerraByte. Putting the Byte back into Terragramming<< Life is like a sheet sandwich you take a bigger piece everyday.
Kensupen
21
Years of Service
User Offline
Joined: 19th Sep 2002
Location: United States
Posted: 30th Sep 2003 22:01
Ok, I've uploaded the code compiled for patch 5.1b. All the code is corrected to work in DBPro 5.1b. The download link is still on the first post. Let me know if anyone finds problems and I'll look into them.

-Kensupen

Nerdsoft Creations - Lead Programmer
System Specs: AMD XP 1700+, WinXP Home, 1GB PC133 ram and Radeon 9500 using DX9
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 30th Sep 2003 22:32
Quote: "I wish you luck. I didn't even want to attempt this in DBC. Too much bubblegum and duct tape."


Ummm... yeah . Consider the dbc version officially too damn slow.

Brains are for idiots.

Athelon XP 1400 Plus - Nvidia Geforce MX400 - 256mb RAM
gbuilder
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: New Zealand
Posted: 1st Oct 2003 23:48
Kensupen,
'I might try to advance the code later to give a smooth height adjustment.'

In the remarks of this excellent code you mention smoothing the height adjustment. Any advance in this area..?

gbuilder.

AMD900mhz, 256mb Ram, 64mb GForce2 MX400 Graphics card, Windows 98se.
Kensupen
21
Years of Service
User Offline
Joined: 19th Sep 2002
Location: United States
Posted: 3rd Oct 2003 09:19
The only thing I was thinking of is making it add to the height until you were far enough away (I think I had 10 units) instead of just placing the camera/object at 10 units away.

-Kensupen

Nerdsoft Creations - Lead Programmer
System Specs: AMD XP 1700+, WinXP Home, 1GB PC133 ram and Radeon 9500 using DX9
gbuilder
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: New Zealand
Posted: 3rd Oct 2003 11:24
Ok,
I've had some success going up stairs as well as ramps, providing the step is not too high. A bit jerky though as it adjusts to the new height..

gbuilder.

AMD900mhz, 256mb Ram, 64mb GForce2 MX400 Graphics card, Windows 98se.
Fallen
21
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Portugal
Posted: 3rd Oct 2003 21:10
I'm making a map in .X to use with your code (with some bad changes #) ) tej problem is the fps that REALLYY decrease.. first time I put a tree with 32000 polys!!!! LOL my mistake #) but even with 4 ou 5 trees with 900 polys the fps are really descrease.. I have a radeon 9700 but honestly I'm thinking that the problem can be mine.. because theres something strange with my radeon.. the fps decrease in other real games to.. confuse !! #)



--Project Fantasy-- WebsitE SooN
Strider
21
Years of Service
User Offline
Joined: 22nd Dec 2002
Location: United Kingdom
Posted: 11th Oct 2003 16:01
Great bit of code Kensupen! My system only squeezed out 96 fps at sync rate = 0, but that's quick enough. Let us know if you fix that jumping routine because it keeps reseting to the start point.

JD
qwe
20
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 11th Oct 2003 21:16
this makes me want to buy dbpro

my system is dell 2.52 ghz, 256 ram, radeon 9500 pro / 9700 (128mb)
my fps averaged 75

this means that if i use this code and have dbpro i can make any level i want as .x format, and not need to do the teedy collision work myself?
what if i added an object during the game? during hte main do loop?
Kensupen
21
Years of Service
User Offline
Joined: 19th Sep 2002
Location: United States
Posted: 12th Oct 2003 01:01
@Strider:
That isn't a jumping routine. It's to reset if you manage to walk out of the map or get stuck in a wall. I could add a jump into it if I get bored, or someone that knows how my code works could do it.

I won't have a lot of time to code in DB now. I just started a new job and it's taking up a lot of my time right now.

@Chris:
My code can be put into a function and you can pass any object to it and it would do all the sliding collision for you. That is why I wrote it. I was tired of not having BSP levels to play with, so I decided to see if DBPro could do the same thing with just an .X level made in CShop or a modeller. This code is what I came up with. It's only accurate to a 45 degree margin. (If a wall is rotated to 22.5 degrees the collision won't be accurate) You can make it accurate to any calculation of degrees, but you will take a massive performance hit. I figure 45 is good enough for any FPS game. Right now, I have it set to do 8 checks every loop for the level. If you add more objects to check against, you just multiply. I'd say 4 could be done without a massive performance hit. (At least on my system)

Play around with it and see what you can do. I made this snippet to help others that want to dive in a make a game but not have to worry about creating their own collision code.
Mine handles:
-Not being able to walk through any wall
-Sliding collision
-Camera height
-Gravity

-Kensupen

Nerdsoft Creations - Lead Programmer
System Specs: AMD XP 1700+, WinXP Home, 1GB PC133 ram and Radeon 9500 using DX9
Akira Tsunami
20
Years of Service
User Offline
Joined: 23rd Sep 2003
Location:
Posted: 12th Oct 2003 06:23
Dude,thats awesome

Be All You Can Be,Be Evil(TM),Hate Microsoft And Support Linux
Raudaschl
21
Years of Service
User Offline
Joined: 25th Dec 2002
Location:
Posted: 12th Oct 2003 16:34
If anyone wants to see the code in action, check out my game. If this post is considered spam then i'll change it.

http://darkbasic.thegamecreators.com/?m=forum_view&t=18267&b=8
qwe
20
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 12th Oct 2003 21:10
kensupen there is an oddity i noticed
when you are in midair when you go straight off a platform or ramp, you can control whether you move forward or backword while in midair.. you can stop and go in midair
qwe
20
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 12th Oct 2003 22:52
also
when the height of an object is lower than your camera height, you hop onto that object if u move into it. this is a bit awkward as u can walk onto a ramp halfway
could you make it so that you walk onto the object if the object is a fourth as high as the camera, so u can only walk onto something if its a natural step height
qwe
20
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 12th Oct 2003 23:22
a question and an observation comparing bsp with your code

in any professional engine ive played that uses .bsp, the computer freaks out when you are out in the middle of no where.. like bsps are only good in enclosed spaces

does .bsp does this in dbpro?

your code does not. i made a huge test map, my fps took no hit no matter what situation
John H
Retired Moderator
21
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Burlington, VT
Posted: 13th Oct 2003 01:31
Kensupen: This is really a great snippet. I tested it out - it kicks! Ya that midair movement thing is kinda odd Its an easy fix tho, just check the distance between the object and the nearest floor and if its greater then whatever, dont respond to up and down keys

Great work

RPGamer

Current Project: Eternal Destiny
We need a texture artist!
If your interested email me - Johnrocs@aol.com
qwe
20
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 13th Oct 2003 23:17
Am I able to edit at what angle you cannot go up any more? It's set too high for me right now, you can go up some of my mountain slopes

How can I leave out an object from the collision?
M00NSHiNE
20
Years of Service
User Offline
Joined: 4th Aug 2003
Location: England, UK
Posted: 14th Oct 2003 01:07
Ive just downloaded the newest version of this code and i must say its some of the most impressive coding work ive seen - not only does the level run smoothly wherever you point the camera now (as opposed to the ropyness of the last version), but its also accurate and fast - WELL DONE!!!

You deserve an award for this

"It's amazin' what you can do with a computer and access to t'internet"
Kensupen
21
Years of Service
User Offline
Joined: 19th Sep 2002
Location: United States
Posted: 14th Oct 2003 07:54
You can adjust the height at which you can "walk" onto an object.

As for controlling the camera while falling, that's a simple IF statement to correct that.

To figure out the angle of what you can/can't walk up, take the distance check to the wall and the distance of the height check. If you lower the height check or lengthen the wall check, you can't walk up as steep of a ramp. Using geometry, you can figure out any angle you want.

This snippet was made to mainly show how you can do sliding collision with just an .X object. I wasn't aiming for a complete FPS engine.

-Kensupen

Nerdsoft Creations - Lead Programmer
System Specs: AMD XP 1700+, WinXP Home, 1GB PC133 ram and Radeon 9500 using DX9
qwe
20
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 15th Oct 2003 03:40
how about a get ground height thing? get the height of the lowest triangle at a particular x,z coordinate
dugzilla
20
Years of Service
User Offline
Joined: 5th Aug 2003
Location:
Posted: 15th Oct 2003 18:06
Your code is awesome!
But I have one problem I can't figure out, my object y position
is 0 and chartht#=50, this puts my object in the air. If I change
charht# to 0 then I cant' walk up ramp. Any suggestions??
Kensupen
21
Years of Service
User Offline
Joined: 19th Sep 2002
Location: United States
Posted: 18th Oct 2003 10:47
@Chris
To do a "get ground height" using just any .X model, just use ht#=1000000-intersect object(1,player position x(#),1000000,player position z(#),player position x(#),-1000000,player position z(#)
I'm not 100% positive this code works, but it's the general idea. (Just wrote it from memory)

@Dugzilla
Leave charht# at 50 and just position your object at where I am positioning the camera -charht#. That way you still get the ramp angle you can walk up, but you just position the object at a "dummy" height.

-Kensupen

Nerdsoft Creations - Lead Programmer
System Specs: AMD XP 1700+, WinXP Home, 1GB PC133 ram and Radeon 9500 using DX9
M00NSHiNE
20
Years of Service
User Offline
Joined: 4th Aug 2003
Location: England, UK
Posted: 18th Oct 2003 16:34
I erckon this should be built into U6.....

It would be cool if there was a 'GET FLOOR HEIGHT' command, bit like the get matrix height command, but it found the height of a 3d object.... this could eradicate the need for the intersect object bit in this code....just a suggestion. Probably a stupid one.

"It's amazin' what you can do with a computer and access to t'internet"
indi
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 19th Oct 2003 08:04
isnt that what intersect object is for moonshime.?

qwe
20
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 19th Oct 2003 17:06 Edited at: 20th Oct 2003 02:47
is there a way to make it so it takes a steeper ramp to fly off it a bit? right now, on a very shallow ramp u bump off the ground for a bit and it feels wierd when ur bumping up and down going down a little hill.

P.S. i still dont get your get ground height
im new to programming, esp new to dbp
could you please give a tested line of code?
M00NSHiNE
20
Years of Service
User Offline
Joined: 4th Aug 2003
Location: England, UK
Posted: 19th Oct 2003 21:45
Just thought it might be faster. Sorry. And its MoonshiNe, indi.

"It's amazin' what you can do with a computer and access to t'internet"
dugzilla
20
Years of Service
User Offline
Joined: 5th Aug 2003
Location:
Posted: 20th Oct 2003 04:55
I still can't get an object to work with this code. If someone could
write an object in with this that would be great. I spent the whole
dang weekend on this......
Kensupen
21
Years of Service
User Offline
Joined: 19th Sep 2002
Location: United States
Posted: 20th Oct 2003 07:51
@Chris:
The way you "walk" down a ramp is that you move forward and then gravity pulls you down. If you don't want it to bump on a small ramp, you'll have to increase gravity. (I think that is a bad idea though) Everquest has this same issue. Every hill you walk down, you constantly fall after you move. As for the Ground height of a model, read up on how Intersect Object works. It's how I made this snippet to begin with. Just play around with the command and built-in objects to see how it works, then apply that to a model.

@Dugzilla:
If I had time, I'd make a new snippet for using a model that walks around the area. As it stands, I just started a new job and it's taking up a lot of my time. I haven't been able to program for a month now. It's too bad the RGT forums got erased. Someone was working on just what you are asking for. I'll let you know if I find the time to convert it to a cube moving around the map.

-Kensupen

Nerdsoft Creations - Lead Programmer
System Specs: AMD XP 1700+, WinXP Home, 1GB PC133 ram and Radeon 9500 using DX9
dugzilla
20
Years of Service
User Offline
Joined: 5th Aug 2003
Location:
Posted: 20th Oct 2003 16:43
Thanks for the help kensupen! I'll keep trying different things,
something has to work sooner or later.
dugzilla
20
Years of Service
User Offline
Joined: 5th Aug 2003
Location:
Posted: 20th Oct 2003 16:44
I'll keep an eye open for any new posts that regard sliding
collision.
gbuilder
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: New Zealand
Posted: 21st Oct 2003 00:17 Edited at: 21st Oct 2003 05:04
This may help,
Here is Kensupen's code changed over to object collision. Of course this means that there is no collision for the camera. What it needs is both, camera and object collision.
Movement is with the mouse buttons. Use Kensupen's level files.

gbuilder.



AMD900mhz, 256mb Ram, 64mb GForce2 MX400 Graphics card, Windows 98se.
dugzilla
20
Years of Service
User Offline
Joined: 5th Aug 2003
Location:
Posted: 21st Oct 2003 02:14
gbuilder,
I've come across this code with a sphere that works well with
itself but when you try to use lets say the colonel z charactor
that came with dbpro,there is a height issue I haven't been able to
figure out. try to set that sphere so it is at ground level not 30
unit in the air and see if you have collision problems with ramp. Or
try out colonel yourself to see if you get a problem like I do?
gbuilder
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: New Zealand
Posted: 21st Oct 2003 03:36 Edited at: 21st Oct 2003 05:59
Yep, I imported the colz.x character and with a bit of tweeking it's on the ground and going up the ramp. Here's what I did..

Change.. 'position object 2,0,charht#,0' to.. 'position object 2,0,charht#-30,0'
Then I lifted up the level a little to 'load object "mslevel.x",1 : position object 1,0,35,0'
Oh, I also reduced the size of the colz.x character by 50%..

Woops, just looked at this again and the character is not exactly on the ground...

gbuilder

AMD900mhz, 256mb Ram, 64mb GForce2 MX400 Graphics card, Windows 98se.
dugzilla
20
Years of Service
User Offline
Joined: 5th Aug 2003
Location:
Posted: 21st Oct 2003 07:38
This code works great with camera but man it is a pain with an object. I haven't any luck with it today,maybe tommorrow..
Dugzilla
feiting
20
Years of Service
User Offline
Joined: 19th Oct 2003
Location:
Posted: 21st Oct 2003 14:48
hey, this is better than Sonic's DLL... and works the same. Except for the sliding part. But anyway, I modified it a bit for some gravity jump effect... it's meant for jumping off ramps. It doesn't work right currently but it's neat how it is. I'll be modifying it to get it to work correctly...

He who does not take the assassin job, will get killed by one who does.
Ronaldaveo
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location: England
Posted: 26th Oct 2003 19:25 Edited at: 26th Oct 2003 20:46
This code is brilliant, there was one thing which prevented me using levels which have minus y co-ordinates (The camera doesn't go below the specified camera height.) so I fixed it for you.

I have basically made my own ramp code based on the supplied, I left the original in there and it can be activated again by removing the remark (so long as you rem out my part). I also added some different movement controlls so that its more fps orientated and a variable to edit the gravity.

You won't notice any difference on the map supplied as its lowest point is 0. Here is the map I tested it with and found the problem, try both ramp codes and try walking off the bridge from the side.

http://stateproperty.users.btopenworld.com/xcol.zip

Very small (250kb) contains the map and the source not required, i'll post the source here too.



[Edit] The Source Button didnt work and I can't edit it so ^^ hopefully this will + A Quick Fix now in the above zip too
gbuilder
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: New Zealand
Posted: 26th Oct 2003 23:01
Refug,
Nice work. Smooth stairs now with that new gravity code. Liked the demo level. Looks like it was made in cshop. When I turned on the lightmap, my old geforce2 struggled a little. Looks good though.

gbuilder.

AMD900mhz, 256mb Ram, 64mb GForce2 MX400 Graphics card, Windows 98se.

Login to post a reply

Server time is: 2024-05-18 06:50:20
Your offset time is: 2024-05-18 06:50:20