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 Discussion / 3d collision

Author
Message
Zach
22
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: Ms, USA
Posted: 10th May 2003 01:23
Does anyone have an example of 3d collision ...Can anyone teach me how to do it.

I know to ..
Tupelo, Ms
Zach
22
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: Ms, USA
Posted: 10th May 2003 02:53
Oh yeah i forgot to mention that the code above does not work....

Tupelo, Ms
Hell IVIonkey
22
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 10th May 2003 04:35
Depends on what type of collision you want. This in turn will depend on what type of game you're making. I almost always will say that math-based collisions are better than DB ones.
Zach
22
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: Ms, USA
Posted: 10th May 2003 06:01
Well, i'm making an RPG and I don't want my character to walk through walls...

Tupelo, Ms
Hell IVIonkey
22
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 10th May 2003 09:50
A tile-based RPG? If so, use math collisions. If not, use DBC collision functions.
sicjoshsic
22
Years of Service
User Offline
Joined: 8th May 2003
Location: United Kingdom
Posted: 10th May 2003 14:05
i think the reason your code doesn't work is that you havn't set objects to detect collision.
e.g.
if object 1 is a cube, then you use SET COLLISION TO OBJECT CUBES 1 (or something like that )

Zach
22
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: Ms, USA
Posted: 11th May 2003 05:13
It's not a tile based rpg it's 3d and i've set the object collision on..forgot to mention that.

Tupelo, Ms
Zach
22
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: Ms, USA
Posted: 11th May 2003 07:04
Ah Ha ... I just figured it out so don't worry about the question above. But another thing i can't figure out is how to get my character to walk up or down a hill .........

Tupelo, Ms
AsriCE
22
Years of Service
User Offline
Joined: 10th Jan 2003
Location: Brunei
Posted: 11th May 2003 10:08
You can use matrices to make the hills and use the "Get Ground Height" command to make your character walk up and down the hill.

Asri CE Crew

Anak Brunei!
John H
Retired Moderator
22
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Burlington, VT
Posted: 11th May 2003 17:31
Yep, you just say like

y#= Get ground height(Matrix Number, x, z)
Position object x#,y#,z#

RPGamer

Current Project: Eternal Destiny
Tech Demo - Colan Island: Currently 716 Lines
arras
22
Years of Service
User Offline
Joined: 3rd Feb 2003
Location: Slovakia
Posted: 13th May 2003 11:35
Turn global colision on
freak
22
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 14th May 2003 01:34
can anyone give me an example of whats meant by 'maths collision' ?
Hell IVIonkey
22
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 14th May 2003 01:41
Use various versions of the distance formula:

Sphere object:
dist = [(x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2]^(1/2)

Cylinder:
dist_xy = [(x2-x1)^2 + (y2-y1)^2]^(1/2)
dist_z = abs(z2-z1)

Box:
dist_x = abs(x2-x1)
dist_y = abs(y2-y1)
dist_z = abs(z2-z1)

Use these general ideas (or variations on them) to test if the coords of object1 are within the bounding box of object 2. Keep in mind that object 1 will have a size greater than a point in space, so adjust your formulas accordingly (usually trial and error method). If a test comes up true, reposition the colliding object.

I actually don't use these formulas much. I ended up writing my own precise AABB (axis-aligned bounding box) system which will always have the player exactly aligned with the face he runs into (never even off by a minutely small fractional value). I had to simulate calculus limits to do it !

freak
22
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 14th May 2003 14:09
so when you want to check if the player collides with an object, you have to check the distance to each object?
so this means you check the distance to every object every frame?
Hell IVIonkey
22
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 14th May 2003 18:25
Yep. If dist<value, then move the player back. If you have a lot of objects, break them up into sectors and only check the player collisions against the objects he's in the same sector with.

freak
22
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 14th May 2003 19:52
that's a good idea, but how will you check collision with objects like walls?
Hell IVIonkey
22
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 14th May 2003 21:03
Rectangle collision (3rd example). If they're angled walls, you can either use trig, or just give up and use the DB collision functions.

freak
22
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 15th May 2003 01:41
what's trig? you mean trigiometry?

it would be only usefull if you could make some editor, for example one in which you can import your world (without moveable objects, doors,...) and then automaticly write some file in which stands how collision has to be checked for each object...

I was thinking about an other method to avoid DB collision... when you had a HUGE, 3-dimensional array in which you store zeros and ones (one if collision has to be detected at that coordinate)
so then you just have to fill in coordinates in that array to know if there's collision or not
I could also make an editor to automaticly generate some file with the array data...

but would this be fast enough? it will really have to be a very huge array if you want some accuraccy...
freak
22
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 15th May 2003 01:44
anyway you cant do it with your rectangle collision method... (or I must have something wrong understood) hmm I'd better test it before judging but I dont have much time now
Hell IVIonkey
22
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 15th May 2003 03:16
Indeed you can. An array of all possible coords is impractical, slow, inaccurate, and huge. It's much better to use trig (and it's spelled (or spelt ) "trigonometry"). This goes hand in hand with vectors. If you know the angle of the face and the vector player motion, you can both calculate the point of incidence (where on that face the player will hit) and the direction and magnitude he will slide. I don't want to discuss how; frankly it's very infeasible and induces too many headaches. Look it up in google if you'd like, or just use BSPs with DB Pro.

freak
22
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 15th May 2003 09:44
do you know how the BSP system works?
Hell IVIonkey
22
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 15th May 2003 11:40
Yep. Which aspect? I've been doing BSP work for about 5 years now.

Hell IVIonkey
22
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 15th May 2003 12:03
Oh, if you're asking me to reproduce the collision code from a BSP engine, there's no way in hell . It took them (id) years to figure out how to do this so that they could make Quake1 (not that this was the only slowdown). If your walls are completely vertical, the problem isn't so hard: the information I've given you should be enough to get started. If you have faces at random orientations, the calculations are beyond most coders' scope.

There was one fella awhile back who derrived the necessary info from a .x file to do this type of collision system. I think his name was TVman or something with a TV in it. I have his demo program "castle.exe," but he didn't include the source. Besides, the collision information was stored in an external (and unreadable) file anyhow.

SonicBoom
22
Years of Service
User Offline
Joined: 26th Nov 2002
Location:
Posted: 15th May 2003 17:42
http://www.darkbasicpro.com/apollo/view.php?t=7058&b=5

is a thread for a dll that is DB & DBPro compatible that can calculate and return to you collision info for stardard .X & .3ds models.
freak
22
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 16th May 2003 01:48
anyway when I've some time I'll check if the huge-array-collision sistem works fast... from one side it could be very slow because it will have to be such a HUGE array, and from the other side there won't be any calculations to check collision, which will be fast... I wonder which of the two effects will win
Hell IVIonkey
22
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 16th May 2003 02:11
It's inaccurate: How do you know what direction to slide for sliding collision? Representing an angled face by rectangles can only make collision more choppy and inaccurate than the built-in DBC functions.

freak
22
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 16th May 2003 02:48
it's not because the collision detection is choppy that moving has to be choppy to... and some collision detection like shooting might be done with another system

how to know in which direction to slide? you can calculate the angle with which you are nearing the wall, so then you can know in which direction to slide
Hell IVIonkey
22
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 16th May 2003 03:25
It will be choppy because the player may get stuck between the "stairs" you've created with rectangles; thus, sliding won't work:


If you hit a wall straight on, you won't slide. If you hit it from 20 degrees, you'll slide some; you'll slide even more at 45 degrees. If your collision is based on fixed-angle blocks, you'll never really know what angle you hit the face, relative to the angle of the face. You'll know your player angle, but not the angle of the wall.

If you think you can do it this way, go for it. I just remain skeptical because I have a fairly good understanding of how vectors work for games.

Zach
22
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: Ms, USA
Posted: 16th May 2003 04:34
Thanks for the help .... sorry i haven't been on the boards for a few days but my grandpa died the 13th......

Tupelo, Ms
Hell IVIonkey
22
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 16th May 2003 04:41
Wow, I'm very sorry to hear that Zach. I hope you and the family are handling it well.

Zach
22
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: Ms, USA
Posted: 18th May 2003 19:43
It's alright...

Tupelo, Ms
arras
22
Years of Service
User Offline
Joined: 3rd Feb 2003
Location: Slovakia
Posted: 21st May 2003 15:21
Its no problem to use vector against face collision, such a calculation you can find in any math book. Problem is that mostly your object is not vector itself but another object, so you have to compare position of all faces of two objects and even to find out if smaller one is not inside bigger one. That means that you have to work not with faces but with spaces between faces.

If I would be you I would use DB collision sistem and make it as effecien as possible. You can have easy and quick distance to size calculation (which most of the people here call math collision, but thats inacurate because every collision detection is based on math calculations) and only if it detect collision I would use DB detection to veryfi result. Like this you can lower number of checks DB collision have to do...

Login to post a reply

Server time is: 2025-05-18 08:32:09
Your offset time is: 2025-05-18 08:32:09