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 / Sliding Collision

Author
Message
G Man
20
Years of Service
User Offline
Joined: 17th Nov 2004
Location:
Posted: 31st Dec 2004 10:18 Edited at: 31st Dec 2004 12:24
Here is a sliding collision routine developed by myself and Lost In Thought. We are still in the process of grooming this code, but it is in a good enough state to be useable. Attached is the media we've been testing this code out with.

As we move along, I will drop back here and update this code. We are working on version to support the Sparky Collision DLL and NGC.

BTW, this code has copius comments so it should be easy to figure out!



Intel Pentium 4, 3.4GHz, 1280MB RAM, NVidia Quadro FX3000/256MB, 240GB HD, XP Pro

Attachments

Login to view attachments
TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 31st Dec 2004 22:00
Pretty good. Very accurate and fairly fast.

Realms Of Tutopia I : Rise Of Evil - A hack+slash RPG
http://www.freewebs.com/elbsoftware/index.htm
Dom
20
Years of Service
User Offline
Joined: 31st May 2004
Location:
Posted: 1st Jan 2005 01:02
Will this work with DeleD files?

DRAGONFIRE STUDIOS
Lead Programmer
(The Studio being my front room)
G Man
20
Years of Service
User Offline
Joined: 17th Nov 2004
Location:
Posted: 1st Jan 2005 03:12
That's what we've been testing it with... Deled files.

Intel Pentium 4, 3.4GHz, 1280MB RAM, NVidia Quadro FX3000/256MB, 240GB HD, XP Pro
TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 1st Jan 2005 05:28
It doesn't matter what program produces the levels as long as they are in .x or .3ds format.

Realms Of Tutopia I : Rise Of Evil - A hack+slash RPG
http://www.freewebs.com/elbsoftware/index.htm
G Man
20
Years of Service
User Offline
Joined: 17th Nov 2004
Location:
Posted: 1st Jan 2005 05:54
I haven't tested it with .3DS levels, although I'd presume they'd work as well.

Intel Pentium 4, 3.4GHz, 1280MB RAM, NVidia Quadro FX3000/256MB, 240GB HD, XP Pro
G Man
20
Years of Service
User Offline
Joined: 17th Nov 2004
Location:
Posted: 1st Jan 2005 06:02
I pull about 480-490 FPS with the test level, what are you all getting?

Intel Pentium 4, 3.4GHz, 1280MB RAM, NVidia Quadro FX3000/256MB, 240GB HD, XP Pro
Lost in Thought
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 1st Jan 2005 07:13
I get 180 to 280 depending on where I am in the level. The collision could be sped up a but if there wasn't so many bugs with DBP's collision system. I get 315 to 360 with the level hidden so our collision only takes appx 3ms to scan that 394 poly level. I am playing with a home made collision checking going by comparing the objects x,y, and z positions to vert loactions. It is buggy and slower so far though. I am not he best 3D mathematician.

TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 1st Jan 2005 22:14
140-220

AMD Athlon XP 2400
Radeon 9600 Pro
512MB RAM

Realms Of Tutopia I : Rise Of Evil - A hack+slash RPG
http://www.freewebs.com/elbsoftware/index.htm
Dom
20
Years of Service
User Offline
Joined: 31st May 2004
Location:
Posted: 1st Jan 2005 22:25
Umm i dont really know but its not very high at all...less then 30

DRAGONFIRE STUDIOS
Lead Programmer
(The Studio being my front room)
Lost in Thought
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 2nd Jan 2005 08:19
Less than 30? What kind of system do you have? If you don't have FRAPS then just modify this part of the code



to this



Dom
20
Years of Service
User Offline
Joined: 31st May 2004
Location:
Posted: 16th Jan 2005 05:36
Quote: "What kind of system do you have?"

A rubbish one


Thanks to Animeblood for the Logo!
Acolyte Entertainment
19
Years of Service
User Offline
Joined: 28th Dec 2004
Location: Oregon, US
Posted: 17th Jan 2005 06:26
hey guys i tried out your code and its awsome i might use some of it for my game. One question though iv tried all of the jumping code i know and its not working on your guyses code any answers?
Dodo
20
Years of Service
User Offline
Joined: 8th Aug 2004
Location: eating lunch
Posted: 27th Jan 2005 00:25
Nice code, but it runs very unstable on my PC. I get anywhere from 300 to 500 fps, max I got was 540, but it keeps jumping randomly.

Part of solving the problem is actually noticing that the problem is there in the first place

Gre4t
20
Years of Service
User Offline
Joined: 6th Nov 2004
Location:
Posted: 27th Jan 2005 21:12
It's nice, but I found the falling quite un-natural.
G Man
20
Years of Service
User Offline
Joined: 17th Nov 2004
Location:
Posted: 29th Jan 2005 02:42
...so make it fall the way you want it to fall, there are coded parameters to adjust the rate of fall to your taste.

Intel Pentium 4, 3.4GHz, 1280MB RAM, NVidia Quadro FX3000/256MB, 240GB HD, XP Pro
moogle
19
Years of Service
User Offline
Joined: 2nd Jan 2005
Location:
Posted: 29th Jan 2005 21:43
it's very nice ! can you think you can add a character collision system ?(with the character followed by the camera) i'm affraid i'm not able to do it

www.whitechaos.tk
Guyon
21
Years of Service
User Offline
Joined: 6th Jun 2003
Location: United States
Posted: 9th Feb 2005 23:24
Gman when I loaded my Bryce .x object into your code all I get is a blank screen with a circle in the middle.

After playing with it, if I rem-ed out both
if Airborn=0 then CheckCollision()
if Airborn=1 then Fall()

I can see my object in the distance, I tried repositioning my object with:
Position Object 1,0,50,0

But it still does not work. I think I am falling before I get to do anything. Can you tell me what is wrong?

I sent you the .x to see if you can figure it out.
Thank you
AlexI
19
Years of Service
User Offline
Joined: 31st Dec 2004
Location: UK
Posted: 9th Feb 2005 23:55
????????????????? does this work in dark basic classic ? ??
AlexI
19
Years of Service
User Offline
Joined: 31st Dec 2004
Location: UK
Posted: 10th Feb 2005 00:01
it works !
but there is no direct x model in it. well in the media file but in the program you start it and theres just a cube?
G Man
20
Years of Service
User Offline
Joined: 17th Nov 2004
Location:
Posted: 10th Feb 2005 02:38
The model is in the .zip file that you get by clicking the "download" button.

Intel Pentium 4, 3.4GHz, 1280MB RAM, NVidia Quadro FX3000/256MB, 240GB HD, XP Pro
Guyon
21
Years of Service
User Offline
Joined: 6th Jun 2003
Location: United States
Posted: 10th Feb 2005 05:30 Edited at: 10th Feb 2005 05:36
Why do I fall up?
Must be my Bryce .x? What do I chance to fall down?
G Man
20
Years of Service
User Offline
Joined: 17th Nov 2004
Location:
Posted: 10th Feb 2005 05:53
You fall up because your Y position goes negative (something which I hadn't take into account when I wrote this. There's two ways to fix it... Fisrt you could go into the fall code and change the code to properly account for the posibility that Y may become negative... or you could fix it the easy way by positioning you model such that no portion of it extends below Y=0.

Intel Pentium 4, 3.4GHz, 1280MB RAM, NVidia Quadro FX3000/256MB, 240GB HD, XP Pro
Guyon
21
Years of Service
User Offline
Joined: 6th Jun 2003
Location: United States
Posted: 10th Feb 2005 05:59
Yes I used this to get my modle in place
Position Object 1,300,-300,300

If I left my model as is, how do I change my start posision?
G Man
20
Years of Service
User Offline
Joined: 17th Nov 2004
Location:
Posted: 10th Feb 2005 06:27
Before the main loop there are two lines. One positions the camera, the other positions the collider. Change these positions to reflect the starting position. In my implementations based on this code, I parameterize these values into StartX, StartY and StartZ variables.

Intel Pentium 4, 3.4GHz, 1280MB RAM, NVidia Quadro FX3000/256MB, 240GB HD, XP Pro
Guyon
21
Years of Service
User Offline
Joined: 6th Jun 2003
Location: United States
Posted: 10th Feb 2005 08:11
Thank you G Man!!!!!!
It works great with Bryce now. The only problem was I had to scale up the Bryce model so big it the editor fogged it out. Can just scale it in DBpro with the same effect?

Also one minor problem I had was, I was using a DBpro version back that would not let me move with the cursor keys.
all is fine now. This is a GREAT piece of code!

Thanks
Rob
Acolyte Entertainment
19
Years of Service
User Offline
Joined: 28th Dec 2004
Location: Oregon, US
Posted: 13th Feb 2005 07:15 Edited at: 13th Feb 2005 07:16
ahg G man please fix your code so you have a cylander as a gun and you can shoot. I just cant get the shooting code to work!












You want fighting...
...you got fighting here: http://www.gamesloth.com/games/fightman.html
G Man
20
Years of Service
User Offline
Joined: 17th Nov 2004
Location:
Posted: 14th Feb 2005 14:57
Quote: "G man please fix your code so you have a cylander as a gun "


Code's not broke. You certainly can have a "cylander" as a gun... You just have to write that part is all. I never said that this code is 100% complete. It is a good starting point and that is all. I've taken care of the sliding collision and falling. Now you take care of the other stuff.

Intel Pentium 4, 3.4GHz, 1280MB RAM, NVidia Quadro FX3000/256MB, 240GB HD, XP Pro
Lost in Thought
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 14th Feb 2005 15:01 Edited at: 14th Feb 2005 15:01
LOL the title says Sliding Collision not First Person Shooter.

Acolyte Entertainment
19
Years of Service
User Offline
Joined: 28th Dec 2004
Location: Oregon, US
Posted: 15th Feb 2005 11:02
iv tryed everything!!!!!!!!!!!!! could u please just add the gun and shooting code thats all!!!!!!!!!!! please

You want fighting...
...you got fighting here: http://www.gamesloth.com/games/fightman.html
The Darthster
22
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 26th Feb 2005 01:35
Quote: "iv tryed everything!!!!!!!!!!!!! "


No you haven't, otherwise you would have already solved it.



Once I was but the learner, now, I am the Master.
See my site for amazing games and demos!
AlexI
19
Years of Service
User Offline
Joined: 31st Dec 2004
Location: UK
Posted: 1st Mar 2005 02:37 Edited at: 1st Mar 2005 02:43
will this code work with at thrid person game. i am gonna use it if it dose .well can i use it, ill give you credit g man


EDIT> i was already making a shooter 1119 lines of code for a james bond game in 3rd person. if i can use the code where do i put it everything is a subrotine

e.g
do
gosub bullets
gosub life
gosub cant be bothered to type the rest
loop
AlexI
19
Years of Service
User Offline
Joined: 31st Dec 2004
Location: UK
Posted: 1st Mar 2005 02:51
sorry for doubble posting but

will this only execute in darkbasic PRO if it will execute in darkbasic calssic then why wont it execute it has a problem with ths line

[b][u][i]Global MovePerSec As Float
G Man
20
Years of Service
User Offline
Joined: 17th Nov 2004
Location:
Posted: 1st Mar 2005 07:50
The code is for DBPro as there are portions that DBC does not support. Additionally it is, as it stands presented from a first-person perspective.

Intel Pentium 4, 3.4GHz, 1280MB RAM, NVidia Quadro FX3000/256MB, 240GB HD, XP Pro
AlexI
19
Years of Service
User Offline
Joined: 31st Dec 2004
Location: UK
Posted: 10th Mar 2005 00:18
DAM IT
Lost in Thought
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 30th Mar 2005 14:01
For those of you who have DBP 5.8 you can remove this section of code as the bug has been fixed



Should give you a speed increase when moving in the +x direction

DeathToll
19
Years of Service
User Offline
Joined: 30th Mar 2005
Location: Kamino or whatever.
Posted: 31st Mar 2005 09:47


ya don't know how much that helped me for what i've been trying to do. that is a great little tutorial you got.
G Man
20
Years of Service
User Offline
Joined: 17th Nov 2004
Location:
Posted: 31st Mar 2005 11:18
Thank you very much!

Intel Pentium 4, 3.4GHz, 1280MB RAM, NVidia Quadro FX3000/256MB, 240GB HD, XP Pro
Shard
20
Years of Service
User Offline
Joined: 3rd Oct 2004
Location:
Posted: 3rd Apr 2005 05:03
Hi G Man,

I just thought that I would let you know how incredibly useful I have found this segment of code.

Before finding this I had spent an inordinate amount of time building a very simple “room” in Game Space and then trying to “walk” around it in DBPro.

The amount that this segment of code has taught me has been a revelation. Brilliant work and thanks very much.

Now, the inevitable couple of questions: As you may guess I have only just started with this 3D stuff, so if the questions appear stupid, please make allowances.

a) The “West wall” problem. Am I right in assuming that this is a bug where the camera can pass right through one of the walls without a collision being detected? If that is correct then even with the extra bit of code in it, I still manage to walk through one particular wall in my “room”. If this is fixed in 5.8, then I will put up with it until the upgrade is released – if not I had better try to figure out what I am doing wrong.

b) When I load the .x file of my “room” into DBPro, I find that I have to scale it by a factor of 500 in each direction to get the sort size that I was working with in Game Space. Is that a pretty normal thing to have to do or am I doing something wrong when I created the model?

Any advice gratefully accepted, and once again thanks for the code you put up on the board – it’s a shame that something like that was not in the manual.
G Man
20
Years of Service
User Offline
Joined: 17th Nov 2004
Location:
Posted: 3rd Apr 2005 19:23 Edited at: 3rd Apr 2005 19:25
The "west wall problem" does indeed manifest itself with the camera passing through the wall. Version 5.8 has appearantly fixed this problem. You may want to go grab the update, knock the lines that LIT indicated out of the code and give it a try.

As for the scaling of the model... The code is written to assume that the character is 64 quants tall. This is a pretty common size for characters to be in first person games. That is however adjustable simply by changing the eyeheight variable's value. I would use care however not to make the character too small as adjusting the camera to operate in such small cramped environments is a serious pain. Additionally you will find that when you are modelling things, it helps to know how large to make them. That way you don't have to scale everything by different amounts to have everything fit together. By deciding how large things are going to be in advance and settling on a scale it makes modelling things that are meant to be used together much easier. For example, you could settle upon a scale of 1 quant = 1 inch. That is roughly the scale I settled on when I wrote this code, thinking that an average person's eye's would be about 5'4" above the ground. (Besides 64 is a common snap to grid value in modeling software)

You may find that if you are scaling your map object in DB Pro 5.7 that the collision detection will be even further off than if you pre-scale it in the modelling software. I seem to recall that being another bug, although I might be wrong. That might account for the problem you are seeing in your one room. The other cause could be a seam that is not completely sealed. In that case, there is the possibility that the collision detection is thrown off. In which case, you will also find that the camera tends to stick to the wall until you reach a corner. So if you notice that symptom happening with this code, then you know the reason why.

On another note, this code also works very well with advanced terrain objects as well. I've mentioned that several other places but not in this thread, so I thought I would sneak it in to this response.

I'm glad you found the snippet useful. That's why LIT and I put it out here. Feel free to drop back and ask any other questions that you may have.

Intel Pentium 4, 3.4GHz, 1280MB RAM, NVidia Quadro FX3000/256MB, 240GB HD, XP Pro
Basic brain
20
Years of Service
User Offline
Joined: 3rd Dec 2003
Location:
Posted: 26th Apr 2005 23:21
This worked really well - until I started to mess around with it...
I loaded .x mesh and then tried to create a skybox / sphere over & around it - but that screwed everything up - I think because the mesh was inside the skybox it was detecting a collision which froze everything...

I thought I had a brilliant work around with set background texture but DBP kicked out an error for that line saying "Command now obselete at line.."

Is there anyway for the collision system to ignore the skybox?
G Man
20
Years of Service
User Offline
Joined: 17th Nov 2004
Location:
Posted: 27th Apr 2005 03:51 Edited at: 27th Apr 2005 03:55
Just set collision off for your skybox/sphere and the problem is gone... I mean you don't want your characters bouncing off the sky anyway right? In fact you never want your characters to ever get close to touching the sky or the illusion would be dispelled.

Intel Pentium 4, 3.4GHz, 1280MB RAM, NVidia Quadro FX3000/256MB, 240GB HD, XP Pro
Lost in Thought
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 29th Apr 2005 14:57
Well in 5.8 public the collision bugs has swapped walls you you will have a slow down again And it was fixed in 5.8 sdk version.

you need to replace the code I posted above



with this



Can't win for losing.

qwe
21
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 26th May 2005 08:00
i get 1000-1200 fps on a 2.5 ghz, 768 ram, radeon 9500/9700
poisoned
19
Years of Service
User Offline
Joined: 6th Jun 2005
Location: the shadow realm
Posted: 6th Jun 2005 17:19
Hello, I'm a noob with dark basic, and this tutorial rox!!! I am learning so much from it!!! Thanks very much.

I found using WSAD for movement works a little better if you use keystate() instead of the k$=upper$(Inkey$())
by using keystate() instead of the variable k$ the movement seems more natural, like using the arrow keys (allows the user to run forward and strafe at the same time)
Mr Bigger
19
Years of Service
User Offline
Joined: 31st Jan 2005
Location: was here!
Posted: 5th Jul 2005 18:51
The south wall collision in this code is off by half the object length.Just thought i would mention this in case the author didnt notice.
Lost in Thought
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 5th Jul 2005 23:09
Yeah it was noticed but it wasn't worth the speed drop to provide a work around like we did with the west wall (no collision at all). You can add it yourself easily though if you feel it is worth the speed drop. Just change the code I posted above to use z instead of x and place it right by that code

Siege1975
20
Years of Service
User Offline
Joined: 27th Jul 2004
Location: UK - Wiltshire
Posted: 14th Jul 2005 11:07 Edited at: 14th Jul 2005 11:08
I'm a little stuck. I've been combining the two examles of this and the one that comes with DBPro. and when you fire you can't move at all for a moment, then the bulelt goes winging off. I've attached the code I'm working on below. Oh and MY jumping is very jerky. Can anyone help please?





Use http://www.whits-end.co.uk For Both Sites
BiggAdd
Retired Moderator
20
Years of Service
User Offline
Joined: 6th Aug 2004
Location: != null
Posted: 14th Jul 2005 22:29 Edited at: 14th Jul 2005 22:35
i get 650-780 Frames per second. nope tell a lie.... i get 900-1000 fps. Its realy good code!


SSDD
Same Sh** Different Day
Vues3d on Kalimee
20
Years of Service
User Offline
Joined: 12th May 2004
Location: NYON (SWITZERLAND)
Posted: 15th Jul 2005 00:00
Hi there!!
I have a sliding collision routine in my gama, but using it it slows down the fps passing from 98fps to 25..! So, what a pleasure to see a new one that probably would help me increase the fps rate..

I will try it next week & will put some comments on it.
Anyway... GREAT work on it Especially for the large comments you wrote.

Guido
http://www.vues3d.com

Login to post a reply

Server time is: 2024-11-24 06:26:14
Your offset time is: 2024-11-24 06:26:14