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 / Distances- i'm Confused

Author
Message
AlexI
20
Years of Service
User Offline
Joined: 31st Dec 2004
Location: UK
Posted: 7th Apr 2005 20:24 Edited at: 7th Apr 2005 20:24
well at the moment i have this code (below)


and when ever you come within a distance of 4000 the program ends how can i turn it round so that when ever you're not in a distance of 4000 the program ens i have tried changing the < to >
AlexI
20
Years of Service
User Offline
Joined: 31st Dec 2004
Location: UK
Posted: 7th Apr 2005 21:34 Edited at: 7th Apr 2005 21:35
if any one knows answer please tell me today anyone REALLY NEED TO KNOW
BadMonkey91
21
Years of Service
User Offline
Joined: 13th Jan 2004
Location:
Posted: 7th Apr 2005 22:08 Edited at: 8th Apr 2005 04:44


To find distance. I did it off the top of my head, I'll check later if people are lynching me.

NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 7th Apr 2005 22:58
!hi!,

The formual you used to retrieve 'distance' is not complete. (objx1#-objx2#)^2 + (objy1#-objy2#)^2 + (objz1#-objz2#)^2. You must make sure to find the square root of the outcome of the math above. So, try sqrt((objx1#-objx2#)^2 + (objy1#-objy2#)^2 + (objz1#-objz2#)^2), and you will then recieve a correct value of 'distance'.

+NanoBrain+
Emperor Baal
21
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 8th Apr 2005 00:40
NanoBrain,

That's not correct

His formula is correct because he checked if the distance was below 4000^2.
Notice the ^2




Should work

NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 8th Apr 2005 13:20
?

+NanoBrain+
Sven B
20
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 8th Apr 2005 20:49
Maybe u should check ur math books...
Or study a bit
AlexI
20
Years of Service
User Offline
Joined: 31st Dec 2004
Location: UK
Posted: 10th Apr 2005 05:48
nooooooooooooooooooooooo
sounds borring, no study, no maths book ('')
waffle
22
Years of Service
User Offline
Joined: 9th Sep 2002
Location: Western USA
Posted: 10th Apr 2005 09:16 Edited at: 10th Apr 2005 09:18
i don't understand what your trying to do ....
based on your code, the game could end reguardless ...

or do you have something like:


part of the problem could be DB use of floats/integers ...
if no 0.0, DB converts to an integer (annoying)
Feugsy
20
Years of Service
User Offline
Joined: 1st Nov 2004
Location: Australia
Posted: 14th Apr 2005 23:29
look i am studying this formula as we speak and this is how to do it mate
place x and place z refer to the place that you are
if sqrt((playerx-place x)^2+(playerz-end place z)^2)<10000 then end

i am fairly sure that this will work
try it
cheers

Timespliiters 2 rocks!
Tom Taylor
21
Years of Service
User Offline
Joined: 29th Dec 2003
Location: Germany
Posted: 16th Apr 2005 05:26
Well you can use this formula, which is very slow and handles very big numbers. But i think in DB you can use vectors like in DBPro?

I have a very fast method, but it depends on how accurate you need your collisions. You can use the VECTOR commands, which are very fast!

Take the X/Y/Z positions from the object and SUBTRACT it from the X/Y/Z position from your player object. Then you can ask for the length of the resulting vector, which is the distance to the object!
This will boost up your performance!

Some code for VECTOR commands:



Simply check the distance "pdist"!

Tom Taylor
Sven B
20
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 16th Apr 2005 17:08
Nope, no vectors in DBC!!
Pricey
22
Years of Service
User Offline
Joined: 22nd Feb 2003
Location:
Posted: 16th Apr 2005 17:58
I am writing this off the top of my head but to find the distance I think its...

dist = sqrt((x1-x2)^2+(z1-z2)^2)

:: 1.8 gHZ AMD Duron :: 256 MB Ram :: 32 MB SiS Graphics ::

:: Current Project: Sea Bound ::
Robot
21
Years of Service
User Offline
Joined: 27th May 2004
Location:
Posted: 16th Apr 2005 18:45
Quote: " Nope, no vectors in DBC!!"


http://forum.thegamecreators.com/?m=forum_view&t=50609&b=10

The happenings of tommorow are behind us now
Baggers
21
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 17th Apr 2005 05:59
Wow ive been quoted !

!hi!: Not meaning to be mean but if you intend on getting good in games programming your going to have to learn to love maths, the more advanced games you attemt the likelyhood is that it will involve more and more complex math.

You could use the vectors (Tom's method looks good) or most of the people have already given you the code.
Hope you have fun with the maths !
Good luck
Sven B
20
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 18th Apr 2005 01:23
I rode that post about vectors.
Sorry to say this, but that code is really buggy. Maybe you can run it, but i can't...
Guitarman
21
Years of Service
User Offline
Joined: 31st Jan 2004
Location:
Posted: 19th Apr 2005 11:33
Ok here's my two cents:

dist#=SQRT((X2-X1)^2+(Y2-Y1)^2+(Z2-Z1)^2)

if dist#<4000
end the program
else
don't end the program
endif

then you can just edit what to do. That is for sure the distance formula. If someone has already posted this, I apologize for repeating. I didn't say it elsewhere.

Quote: "Not meaning to be mean but if you intend on getting good in games programming your going to have to learn to love maths, the more advanced games you attemt the likelyhood is that it will involve more and more complex math."


(Now you've been quoted twice) But you have a great point. I find thngs easier with more and more math experience.
AlexI
20
Years of Service
User Offline
Joined: 31st Dec 2004
Location: UK
Posted: 19th Apr 2005 22:38
and then if i was to use that code i would use this at the top:


x1# =object position x(1001)
y1# =object position y(1001)
z1# =object position z(1001)

x2# =object position x(2000)
y2# =object position y(2000)
z2# =object position z(2000)

Login to post a reply

Server time is: 2025-06-01 02:17:41
Your offset time is: 2025-06-01 02:17:41