Did you ever yoused the 3D Distance function or wondered on what the Distance between you and your Enemy depends on?

Well here I will show you what it actually does and how you can write your own one. If you already know how it works, that's good. If not this could be useful to understand the Math behind it all, so you can come up with new ideas.

Before we start you should have a basic understanding of Math, that's all. Also im sorry for my bad English, I am german.

Well here I will show you what it actually does and how you can write your own one. If you already know how it works, that's good. If not this could be useful to understand the Math behind it all, so you can come up with new ideas.

Before we start you should have a basic understanding of Math, that's all. Also im sorry for my bad English, I am german.

In this picture you can see a Three Dimensional Coordinate System.

So now i will add to Points to the System. I will call them A and B because that's what you usually do. A will be our Player.

They have the Coordinates: A = (-4.70635, 2.31164, 1.63883) and B = (3.18464, 3.96405, 2).

So now we "Pull a line between the two Points" or "Create a Vector that represent quantities that have a magnitude and als a direction".

So the Vector has the Coordiantes X (7.89) Y (1.65) Z (0.36).

How to you Calculate this? Its very Simple:

Because we start at A and got Towards B, our Tip is at B.

So now you have to Subtract the X Coordinate of B from the X Coordinate of A.

When you do the same with the Y and the Z Coordinates you will get the Value of the Vector AB.

XB - XA = X

YB - YA = Y

ZV - ZA = Z

Well now all thats left is to Calculate the Magnitude of the Vector.

We will achieve this with Pythagoras' Theorem. Well there was a smart Guy about 2000 Years ago who found out that when a triangle has a right angle and squares are created on each of the three of the triangle sides, then the biggest square has the same area as the two smaller squares put together. The Equation is called: aÂ² + bÂ² = cÂ².

We will achieve this with Pythagoras' Theorem. Well there was a smart Guy about 2000 Years ago who found out that when a triangle has a right angle and squares are created on each of the three of the triangle sides, then the biggest square has the same area as the two smaller squares put together. The Equation is called: aÂ² + bÂ² = cÂ².

This is how its done:

|AB| = √( XÂ²+ YÂ²+ ZÂ²) = Magnitude

|AB| = √( 7,89Â² + 1,65Â² + 0,36Â²) = √(65,1042) = 8,0687

As the Coordinates are only correct to two decimal places, the Valid digits are only 8,07.

And this is the Magnitude between you and the Enemy.

So here you are thats all to it.

Have a Great Day,

fx705HUJX0

Last edited: