## Recommended Posts

Hi all,

Any suggestion about all commands referring to distance (between 2 objects)?

About distance calculation, I found few difference between the commands:

Example: player at [4142.04,4569.92,0] , object: o1 at [4165.75,4751.43,0]

player distance o1                 // 188.577   algorithm applied to center?

player distanceSqr o1           // 35561.1  (sqrt 188.577)

getPosASL player vectorDistance getPosASL o1   // 188.906

same as:   getPosATL player Distance getposATL o1

same as: sqrt((getPosASL o1 #0 - getposASL player #0)^2 + (getPosASL o1 #1 - getposASL player #1)^2 + (getPosASL o1 #2 - getposASL player #2)^2)

As reminder: player distance2D o1       // 183.064  sqrt((getPosASL o1 #0 - getposASL player #0)^2 + (getPosASL o1 #1 - getposASL player #1)^2)

probably used in radius of trigger, distance 2D for nearestObjects...

About performance, if you don't need precision, just using a distance filter for objects in vicinity of player, not so much difference between:

player distance o1 < 200 (sphere)

player distanceSqr o1 < 40000 (sphere)  // perhaps a little better in performance

player distance2D o1 < 200 (cylinder)    // perhaps a little better in performance.

And you, how do you check distances?

• 1

##### Share on other sites

mostly I use distanceSqr. I thought bout if distance2D is faster but never tested it.

With nearestObjects I use 2d mode as well.

• 1

##### Share on other sites

@pierremgi I usually just use distance2D for my calculations between flying helicopter and specific point I'm using on the map.

The link gives a good picture, which I'm sure you have seen.

Difference?  Probably only minimal.

##### Share on other sites

I tried to measure the difference between distance, distanceSqr and distance2D in the debug console but without success. I could not see any difference in performance between these 3 commands.

##### Share on other sites

distance2D skips the elevation (as shown above). That's faster than vectorDistance.

The distanceSqr avoids the sqrt calculation, probably non significative for our CPUs.

Distance seems to have its own algorithm, i didn't find but i didn't test comparison with vector between centers of models.