Jump to content
Sign in to follow this  
zorilya

'Distance to location' inaccurate

Recommended Posts

i've observed on a few occasions now that when getting the distance between a unit and a map location of any type i.e. _location = nearestLocation [(getpos this),"NameCityCapital"];

the distance comes back at around 70 units out (i think meters). try it yourselves get a location by the above means and then do something like hint (str(_unit distance (getpos _location))); when your standing right on the location.... i've tried making a marker so i know that i am at the center and it's off by around 70.

any thoughts?

Share this post


Link to post
Share on other sites

Locations are have a height (Z) of 0m ASL, while the position of the unit is 3d. The distance you are seeing in the hint is the height of the unit above sea level.

Edited by ceeeb

Share this post


Link to post
Share on other sites

thankyou very much....

so i take it getposATL _location would do a better job since it is on the terrain that i would be measuring the distance from?

Edited by zorilya

Share this post


Link to post
Share on other sites

I use BIS_fnc_distance2D (need the BIS function module) to get distances from locations and it seems to work fine.

Share this post


Link to post
Share on other sites

just tested the

(getPosASL_unit) distance (getpos _location)

little bit of an issue. now i'm getting a 130m discrepancy between the distances. this makes me think that location positions are in mid air... which makes more sense for air units and stuff...

can't use getPosATL _location because getposATL doesn't accept locations only objects..... i guess i could spawn an object and getPosATL that but that is a bit much i think.... gonna look for another way round.

Share this post


Link to post
Share on other sites

If you want guaranteed 2D distance you can use something like:

[(getPosATL _unit) select 0;(getPosATL _unit) select 1,0] distance (position _location);

if in 3D between two points on ground level one where unit is, second, where location is, then:

[(getPosASL _unit) distance [(position _location) select 0,(position _location) select 1,getTerrainHeightASL [(position _location) select 0,(position _location) select 1]];

Share this post


Link to post
Share on other sites

Did you try the BIS_fnc_distance2D? Like I said, it works perfectly fine for me using locations. Or you can take a look at what that function is doing if you don't want to include the BIS function module and just use the code.

But, if you call their function what you'll want is something like this:

_distance = [getPos _location, _unit] call BIS_fnc_distance2D;

And yes, distances are meters.

I've been using it in my orienteering missions and it works perfectly. I've plotting maybe a couple of hundred locations. I've been able to pinpoint my location down to I would guess a few meters.

Share this post


Link to post
Share on other sites

2D distance between "_object1" and "_object2" without the functions module:

_d = [(position _object1) select 0, (position _object1) select 1, 0] distance [(position _object2) select 0, (position _object2) select 1, 0];

Share this post


Link to post
Share on other sites

If you are already loading CBA, you do not need to place functions module on the map, as it is pre-loaded with CBA...

Share this post


Link to post
Share on other sites
just tested the
(getPosASL_unit) distance (getpos _location)

little bit of an issue. now i'm getting a 130m discrepancy between the distances. this makes me think that location positions are in mid air... which makes more sense for air units and stuff...

can't use getPosATL _location because getposATL doesn't accept locations only objects..... i guess i could spawn an object and getPosATL that but that is a bit much i think.... gonna look for another way round.

I've had another look at this. Some (engine created?) locations are at 0m ATL.

Example:

getpos (nearestLocation [(getpos player),"FlatArea"])

returns [4324,3518.44,-32.1644]. This is a config defined 2d location, so z=0m ASL.

However,

getpos (nearestLocation [(getpos player),"Mount"])

returns [4300,3510,0]. This is an engine created location, with z=0m ATL.

So, to return the position of any location in either ASL or ATL, you will need to use an if then test, using either ASLtoATL or ATLtoASL to switch when required. Or just manually use 0 ATL for the z value of all locations as Rydygier suggests :)

Edited by ceeeb

Share this post


Link to post
Share on other sites

Thanks for the input guys much appreciated, i have gone with just creating and hiding and object as they create at the real terrain level, but no doubt i will end up changing that as i can't imagine it to be the most efficient way. The feedback on asl and atl is very helpful and i will keep it in might in future.

thought i might mention i think this might also be related to waypoints too but i haven't tested it yet. just been having issues with units not getting withing 50m of a waypoint (with completion set to 20) before they decide to bug out to the next one.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×