Talk:GetDistance - ObjectReference
For Skyrim, this function uses the Pythagorean Theorem for calculating distance on a 3D coordinate plane. For Fallout 4, it should be the same, however taking notice of the bug reported, there might be a fault in the underlying code. Either way, you can code your own GetDistance function to be a bit more efficient, assuming the vanilla counterpart relies on calling Pow - Math three times, as well as internally getting the x,y,z positions of BOTH objects, which is certainly not efficient and slow. To avoid using math.pow, simply multiply the x-x, y-y, z-z differences with themselves(power of 2), then pass the results to Sqrt - Math. For getting the x,y,z positions of both objects, this needs to stores outside of your custom distance function. The idea being to a make custom function that only has to make an external call to just one native function: Sqrt - Math. The rest is all just multiplication and subtracting. No calling 2 functions/subroutines a total of 9 times under the hood. Again, assuming it's coded that way. --Rasikko (talk) 2018-05-30T01:15:30 (EDT)
Compact big numbers
I bring to you the "Cell Unit". Where 1 cell = a distance of 4,096 skyrim units! Instead of looking at large numbers for this function, convert to the cells instead.
Game.GetPlayer().GetDistance(Obj) * 4096.0
; Let's pretend the Obj is 23,500 skyrim units away. This becomes 5.7 cells away from the player.
; 200,000? 48.8
; What about 1,000,000? 244.1 cells.