How to manually calculate distance location between two objects

Hi There,

Is there a way to calculate the distance between two xyz coordinates manually.

I just need to double check the values I get in game are correct

Would really appreciate a straightforward way to do this for someone extraordinarily bad at maths!

Hi Delta,

something like this:

sqrt( sqr(v2.x-v1.x) + sqr(v2.y-v1.y) + sqr(v2.z-v1.z) )

Squaring the delta’s removes any signs.

2 Likes

subtract the position of one thing from the other, this gets you the difference between the two, the vector

because we only care about the absolute value of the vector, use the…absolute value (lol) to drop the sign (we don’t know what order you did the first step, (a - b) or (b - a) wont matter if we use absolut-value

get the length of that vector

there should be nodes in BPs or commands on C++ to do this. I know there is also a Distance node or VectorLength in Materials if you are doing your maths there…

Hi RD, huge thanks, but if its not too much trouble,could you please give me a worked example?

Any chance of a worked example please?

Here you are:

2 Likes

Nice, however if I wanted to do the calculation on paper could you walk me through how to do it given 2 X,Y,Z coordinates

Ok, it’s just really pythagoras’ theorum but in 3D (Hypotenuse squared = Adjacent squared + opposite squared)

so say you have two vectors 1=(0,0,0) 2=(100,100,100), you would calculate it by:

x part = (0-100) * (0-100) = -100 * -100 = 10000
y part = (0-100) * (0-100) = -100 * -100 = 10000
z part = (0-100) * (0-100) = -100 * -100 = 10000

so then

distance squared = 10,000 + 10,000 + 10,000
or
distance = square root of (30,000)

distance = 173.2

1 Like

Huge thanks!

1 Like