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.

Newcomers DBPro Corner / intersect object collision

Author
Message
Basic brain
20
Years of Service
User Offline
Joined: 3rd Dec 2003
Location:
Posted: 29th Apr 2005 22:32 Edited at: 29th Apr 2005 22:33
I've been struggling for about a week now with collision for my .x levels & from the posts I've read here I think I need to use an intersect object.
Trouble is everything I've read about intersect objects (codebase & forums) has not really helped me understand it...
Maybe I'm just dumb...maybe it's just Friday afternoon but:

"Intersect Object is a command that returns the distance to an object"



If anyone can explain this to me (using sock puppets where necessary) I'd be grateful...
Lost in Thought
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 29th Apr 2005 23:18
There are a couple of codes in the code snippets forum. DBP's collision commands are totally screwed in DBP 5.8 public. It is aggravating but I would find the 5.8 dsk runtime version as it was almost perfect in it . Intersect object seems to be working though. Basically it just casts an invisible line where you tell it to and it returns the distance to the object you specify if it intersects the line.

SYNTAX
Return Float=INTERSECT OBJECT(Object Number, X, Y, Z, ToX, ToY, ToZ)

the line will be from the x,y,z coords and travel to the tox, toy, toz coords and if it hits the object specified it will tell you the distance from the x,y,z coords to where it hit the object.

Basic brain
20
Years of Service
User Offline
Joined: 3rd Dec 2003
Location:
Posted: 30th Apr 2005 00:04
I searched for "intersect" and got 3 results from the codebase & they all confused the hell out of me.
I know the syntax. But knowing what to type is different from knowing what it does & how to use it.
On the plus side, I just had a pepsi and think I'm starting to figure it out - can u tell me:

a. Where should this line go in relation to my camera?
i.e. If I want to know the camera height from my .x level the line should go straight down from my camera position? (and can the X,Y,Z and ToX,ToY & ToZ be variables e.g camerapositionX#?)

b. So how do I use the position of another object for collision?
i.e. once I know how high my camera is from the .x level, do I check that it is more than a set height (like 10), and if not reposition? something like:


c. Would I have a line in going out from my camera on all sides in case I run into a wall or something?
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 30th Apr 2005 02:53
cast a vertical ray from above ground to below ground (or x level) exactly at your camera x and z positions , something like:

ivalue#=intersect object(my_x_level,camerapositionX,1000,camerapositionz,camerapositionX,-1000,camerapositionz)

points to bear in mind:

the plus and minus vertical values must be bigger than your highest and lowest points in the level,or you will miss some spots.
i.e. if your highest spot is supposed to be at y#=2357 you must cast at least from +3000, same logic with the lowest spot..( i normally cast from +10000 to -10000 to be sure)

in upgrade 5.8 the command works only from top to bottom (i.e. like from +1000 to -1000 and not from -1000 to 1000) or better explained, only toward the polygons with positive normals.

you must adjust the values for the correct height units:
if you cast from 10000 to -10000 your height relative to y#=0 will be:
groundheight#=10000-ivalue#

hope it helps
Basic brain
20
Years of Service
User Offline
Joined: 3rd Dec 2003
Location:
Posted: 3rd May 2005 21:10
Thanks I'll give it a try.

Any ideas on wall collision as per c.?
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 4th May 2005 04:38
walls collision is a bit trickier and it 's difficult to achieve excellent results with basic code..
what you can do is to cast a ray forward horizontally from camera position like 1000 units far ahead and manage the camera routine when the intersect value is below a certain amount ( say 30 units or so )

To cast a ray horizontally you must find the "to" x and z spots at like 1000 units (just an example,use whatever needed ) ahead of the camera :

tox#=newxvalue(camera position x(),camera angle y(),1000)
toz#=newzvalue(camera position z(),camera angle y(),1000)

then cast your ray

frontintersect = intersect object(x_level,camera position x(),cameraheight#,camera position z(),tox#,cameraheight#,toz#

if frontintersect < 30 then .......manage camera

if your walking backwards ( but without turning) you can set 1000 to -1000 in the tox , toz calculation and cast as above ( it changes the to location behind the camera)

this is very basic tho, it doesn't consider strafing and you may find you get the cam stuck to the walls ( i.e. no sliding collision, unless you write your own routine)

Login to post a reply

Server time is: 2024-09-23 19:24:45
Your offset time is: 2024-09-23 19:24:45