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 / Recording distance between two objects (DBPRO)

Author
Message
Tom J
19
Years of Service
User Offline
Joined: 4th Aug 2005
Location: Essex, England
Posted: 24th May 2006 19:47
Is there a command I can use to find out the distance between two objects? Thanks in Advance.

Let the games begin
Mr X
19
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 24th May 2006 20:51
No, there isnt. But you can make a function that does it with ease.
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 24th May 2006 21:05
You could even try using the search facility on this forum and search for 'distance'. Question has been asked and answered many times. Pointless re-inventing the wheel.

Boo!
Gil Galvanti
19
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 24th May 2006 23:08
just use the distance formula . distance=sqrt(( x1-x2 ))^2) + (( z1-z2 ))^2 ))

Pirates of Port Royale
Live the life of a pirate.
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 25th May 2006 13:55
Woo! First to post this!

People like to use vectors for distance in DBPro, which are fast, but for some reason their functions only use one vector number, so this is my version:




Untested btw.

DK_
20
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 26th May 2006 18:25 Edited at: 26th May 2006 18:40
Just to expand a little on what Gil Gavanti said, many people don't know this, but to calculate distance in more than 2 dimensions you simply add to it. So the distance formula in 3D is:

(x1-x2)² +(y1-y2)² +(z1-z2)² =distance²

@zotoaster:
that code does work, except it doesn't print anything to the screen, so to fix that I just moved the 'dist#=getdist()' function call to before the do:loop and put a command to print 'dist#'.


Available for programming position using DBPro.
Also, good at multiplayer coding, contact at:
laptop5002@hotmail.com
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 26th May 2006 20:25
@DK_

Oops a daisy
Well aslong as it works I'm fine.

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 26th May 2006 22:21
I thought anyone passed 7th grade knew the Pythagorean theorem by now.
http://regentsprep.org/regents/math/fpyth/Pythag.htm

"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike
ThinkDigital
19
Years of Service
User Offline
Joined: 18th Aug 2005
Location: A galaxy far, far away...
Posted: 27th May 2006 07:48
Assuming it works in 3 dimensions, that's what they're doing.
Tom J
19
Years of Service
User Offline
Joined: 4th Aug 2005
Location: Essex, England
Posted: 27th May 2006 17:06
Thanks for all the help!
All those ways of working out the value of a distance have really helped me with my game!

The Url to my site actually works now!
John H
Retired Moderator
22
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Burlington, VT
Posted: 28th May 2006 08:29
Dont use the pythagorean theorem in DB, SQRT() is slower than death.


Join Our Forums and get game updates faster!
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 28th May 2006 11:39
And yet, strangely SQRT(x) is quicker than x^.5

Anyone know why???
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 28th May 2006 23:23
If you only need the distance to compare objects, then compare their squared distance. meaning dont use sqrt() as John said.

"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 29th May 2006 22:42
well, ppl already told you about this and all i can help you is showing my distance functions


Too Sexy
Darkhorse
18
Years of Service
User Offline
Joined: 21st May 2006
Location: Manchester UK
Posted: 31st May 2006 23:42
Quote: "I thought anyone passed 7th grade knew the Pythagorean theorem by now.
http://regentsprep.org/regents/math/fpyth/Pythag.htm"


Thanks for that link. I think it may come in useful as it's been a while since I left school.

Login to post a reply

Server time is: 2024-11-27 18:37:42
Your offset time is: 2024-11-27 18:37:42