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 / distance between two objects

Author
Message
Lame Brain
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location: Portland, OR
Posted: 14th Nov 2005 17:02 Edited at: 14th Nov 2005 17:05
This one is silly, I should know this.

can somebody remind me how to find the distance between two objects?

also, how do I find what angle an object is in relation to another object? like for instance if I have a ship that needs to go to a target, how do I find out what angle to turn the ship to in order to travel straight to the target?

Another hair-brained idear from... LAME BRAIN!
David iz cool
19
Years of Service
User Offline
Joined: 21st Sep 2005
Location: somewhere lol :P
Posted: 14th Nov 2005 17:31
the 2nd question is easy as pie

point object "whatever object u want the ship to point at."

Lame Brain
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location: Portland, OR
Posted: 14th Nov 2005 18:00
thats true, I could just point my object at it and then read the object angle, but what's the mathmatical way of doing it?

Another hair-brained idear from... LAME BRAIN!
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 14th Nov 2005 19:41
atanfull(xdiff, zdiff) calculates the angle between 2 points.

Immunity and Annihalation makes Immunihalation...
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 14th Nov 2005 20:22 Edited at: 14th Nov 2005 20:23
thats only the y angle

edit:

to get the distance you ca use pythagoras theorem, or use vectors..


Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 14th Nov 2005 20:26
What does it matter?

atanfull(xdiff, ydiff) is the xangle
atanfull(xdiff, zdiff) is the yangle

Immunity and Annihalation makes Immunihalation...
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 14th Nov 2005 20:48
ah, yes, well I tried that, it didnt work...


Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 14th Nov 2005 21:39 Edited at: 14th Nov 2005 21:46
I wrote such a code once. For a guy that needed a missile to follow it's target. It didn't work for moving missiles though, but it worked great for turret-gun AI.

*Searching my pc for the code now

[edit]

found it!



I knew it worked
[edit] sorry, code not working. Fixed

Immunity and Annihalation makes Immunihalation...
Robin
21
Years of Service
User Offline
Joined: 22nd Feb 2003
Location: United Kingdom
Posted: 15th Nov 2005 00:34
To find the distance between two 3D points is simply an extension of pythagoras - square the x, y and z distances between the two points, add the three results together and then square root the total.
Hope I helped,
Robin

http://www.robinsgames.com | robin@robinsgames.com

Health Food Makes Me Sick
Lame Brain
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location: Portland, OR
Posted: 15th Nov 2005 06:00
Doing some more checking, and I found someone mentioned that squareing and square-rooting slows the program down, someone mentioned using vectors as an alternative. I've been looking up vectors (even found a nifty tutorial on them, check it out: http://www.kentaree-studios.com/tutorials/vectors/,)
This is cool, it is helping me a lot, I'm just not sure I have it yet, but I'm working on it.

Now the other question, does any body have a spiffy equation to find what angle an object is, relative to another object? example, object 1 is at 25,25 and object 2 is at 50,50, how do i calculate that if object 1 travels at a course of 135 it will reach object 2? How do I do this in 3D?

Thank you for your time

Another hair-brained idear from... LAME BRAIN!
Freddy 007
19
Years of Service
User Offline
Joined: 30th Nov 2004
Location: Denmark
Posted: 15th Nov 2005 09:45 Edited at: 15th Nov 2005 09:56
I wrote a function for calculating distance between two objects(using Pythagoras):




I can't be fired... Slaves are SOLD!

Login to post a reply

Server time is: 2024-09-24 09:36:12
Your offset time is: 2024-09-24 09:36:12