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 / Help - distance

Author
Message
slurch901
21
Years of Service
User Offline
Joined: 20th Jan 2004
Location: ESPAÑA
Posted: 22nd Feb 2004 20:15
could sum 1 tell me how to make a piece of code which says sumthing when the player gets to close to it (anywhere around it :/)

here is a small pic of that i want

.........................
.. ..
.. ..
.. door ..
.. ..
.. ..
.........................
dist 10

........ <--- player

ty
ico2
21
Years of Service
User Offline
Joined: 3rd Jan 2004
Location:
Posted: 22nd Feb 2004 21:00
try comparing x,y,z positions of objects and when they are near, then execute your code.
slurch901
21
Years of Service
User Offline
Joined: 20th Jan 2004
Location: ESPAÑA
Posted: 22nd Feb 2004 21:55
ty n e way dude but i knew what i had to do its just i aint to sure how to do it so if sum 1 could help me it would be greatly appriciated
hexGEAR
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Naytonia
Posted: 22nd Feb 2004 22:14 Edited at: 22nd Feb 2004 22:36
dist# = sqrt((x1-x2)^2+(y1-y2)^2+(z1-z2)^2)

where

x1,y1,z1 = 3D coordinates of object 1
x2,y2,z2 = 3D coordinates of object 2

dist# gives you a value you can use to compare how close to object are to one another. so you could say something like:

if dist# < 5.0 then do something

slurch901
21
Years of Service
User Offline
Joined: 20th Jan 2004
Location: ESPAÑA
Posted: 22nd Feb 2004 22:59
thx dude for the code but it doesnt seem to work :/

are u sure that is right?

hexGEAR
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Naytonia
Posted: 23rd Feb 2004 01:21 Edited at: 23rd Feb 2004 01:22
i hope you didn't type it down "as is" 'cus i just put it up there for illustration...

the real code would look something like this

function dist(obj1,obj2)

rem log object 1 coordinates
x1# = object position x(obj1)
y1# = object position y(obj1)
z1# = object position z(obj1)

rem log object 2 coordinates
x2# = object position x(obj2)
y2# = object position y(obj2)
z2# = object position z(obj2)

rem calculate distance
dist# = sqrt(sqr(x1#-x2#)+sqr(y1#-y2#)+sqr(z1#-z2#))

endfunction dist#

rem returns the square
function sqr(x#)
endfunction (x#*x#)

i think that should work, maybe some slight spelling errors or wrong command names but try it out. You should call the "dist" function with the object ID's of the two objects you want to find the distance between. Assign the result to a variable, so something like:

objdist# = dist(1,2)

that should store the distance between object 1 and 2 in the variable "objdist#". Try to understand what's actually going on rather than copying and pasting the code and seeing if it works or not, it helps the learning process

slurch901
21
Years of Service
User Offline
Joined: 20th Jan 2004
Location: ESPAÑA
Posted: 23rd Feb 2004 19:16
TY VERY MUCH i had to change it slightly but TY again

maybe you could put the code in the code base to help others instead of having to answer every single person

TY AGAIN!!!!!!!!!!!!!!!!!!!!!!!1
Emperor Baal
21
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 23rd Feb 2004 19:53
Hexgear, ^2 works in darkbasic no need for a square function


Quote: "
Amd 2500+ | 1024mb pc2700 | A7N8X-X | Geforce4 ti 4200 128mb
"

Login to post a reply

Server time is: 2025-05-23 03:08:00
Your offset time is: 2025-05-23 03:08:00