Difference between revisions of "Position"

From Bohemia Interactive Community
Jump to navigation Jump to search
(New limits)
m (Add Category:Scripting Topics category)
Line 1: Line 1:
==Introduction==
+
{{SideTOC}}
 +
== Introduction ==
  
 
Positions in Arma could be either '''2D''', in which case it is in format '''[x,y]''', where '''x''' is the coordinate on the ''West'' – ''East'' axis and '''y''' is the coordinate on ''South'' – ''North'' axis, or '''3D''', in which case it is in format '''[x,y,z]''', where '''z''' is the height. The height relative to exactly what differs depending on the format of '''3D''' position used.  
 
Positions in Arma could be either '''2D''', in which case it is in format '''[x,y]''', where '''x''' is the coordinate on the ''West'' – ''East'' axis and '''y''' is the coordinate on ''South'' – ''North'' axis, or '''3D''', in which case it is in format '''[x,y,z]''', where '''z''' is the height. The height relative to exactly what differs depending on the format of '''3D''' position used.  
 
<br><br>
 
<br><br>
 
{{Warning | Since Arma 3 v1.93.145664 position values are limited to [-50km/+500km,-50km/+500km,-50km/+500km]}}
 
{{Warning | Since Arma 3 v1.93.145664 position values are limited to [-50km/+500km,-50km/+500km,-50km/+500km]}}
==Formats==
+
== Formats ==
  
 
:There are a number of formats available in the game:
 
:There are a number of formats available in the game:
Line 22: Line 23:
 
:[[Image:position.jpg|600px]]
 
:[[Image:position.jpg|600px]]
  
==PositionASL==
+
== PositionASL ==
  
 
:'''z''' is measured from the sea level which is constant across the map.
 
:'''z''' is measured from the sea level which is constant across the map.
  
:<u>Related commands</u>:
+
:<u>Related commands:</u>
  
 
:[[getPosASL]], [[setPosASL]], [[getPosASLVisual]], [[visiblePositionASL]], [[ASLToATL]], [[ATLToASL]], [[AGLToASL]], [[ASLToAGL]], [[eyePos]], [[aimPos]], [[getTerrainHeightASL]], [[lineIntersects]], [[lineIntersectsWith]], [[lineIntersectsObjs]], [[lineIntersectsSurfaces]], [[terrainIntersectASL]], [[playSound3D]], [[setDefaultCamera]]
 
:[[getPosASL]], [[setPosASL]], [[getPosASLVisual]], [[visiblePositionASL]], [[ASLToATL]], [[ATLToASL]], [[AGLToASL]], [[ASLToAGL]], [[eyePos]], [[aimPos]], [[getTerrainHeightASL]], [[lineIntersects]], [[lineIntersectsWith]], [[lineIntersectsObjs]], [[lineIntersectsSurfaces]], [[terrainIntersectASL]], [[playSound3D]], [[setDefaultCamera]]
Line 34: Line 35:
 
:'''z''' is measured from the surface of the sea that could be higher or lower than sea level due to waves.
 
:'''z''' is measured from the surface of the sea that could be higher or lower than sea level due to waves.
  
:<u>Related commands</u>:
+
:<u>Related commands:</u>
  
 
:[[getPosASLW]], [[setPosASLW]]
 
:[[getPosASLW]], [[setPosASLW]]
  
==PositionATL==
+
== PositionATL ==
  
 
:'''z''' is measured from the terrain level which varies across the map.
 
:'''z''' is measured from the terrain level which varies across the map.
  
:<u>Related commands</u>:
+
:<u>Related commands:</u>
  
 
:[[getPosATL]], [[setPosATL]], [[getPosATLVisual]], [[ASLToATL]], [[ATLToASL]]
 
:[[getPosATL]], [[setPosATL]], [[getPosATLVisual]], [[ASLToATL]], [[ATLToASL]]
  
==PositionAGL==
+
== PositionAGL ==
  
 
:'''z''' is the same as in [[PositionASLW]] when over sea and is the same as in [[PositionATL]] when over land. Most commands either take or return [[PositionAGL]].
 
:'''z''' is the same as in [[PositionASLW]] when over sea and is the same as in [[PositionATL]] when over land. Most commands either take or return [[PositionAGL]].
  
:<u>Related commands</u>:
+
:<u>Related commands:</u>
  
 
:[[modelToWorld]], [[worldToModel]], [[modelToWorldVisual]], [[worldToModelVisual]], [[positionCameraToWorld]], [[intersect]], [[terrainIntersect]], [[isOnRoad]], [[drawIcon3D]], [[drawLine3D]], [[distance]], [[moveTo]], [[doMove]], [[move]], [[setDestination]], [[buildingPos]], [[screenToWorld]], [[worldToScreen]], [[AGLToASL]], [[ASLToAGL]], [[unitAimPosition]], [[unitAimPositionVisual]]
 
:[[modelToWorld]], [[worldToModel]], [[modelToWorldVisual]], [[worldToModelVisual]], [[positionCameraToWorld]], [[intersect]], [[terrainIntersect]], [[isOnRoad]], [[drawIcon3D]], [[drawLine3D]], [[distance]], [[moveTo]], [[doMove]], [[move]], [[setDestination]], [[buildingPos]], [[screenToWorld]], [[worldToScreen]], [[AGLToASL]], [[ASLToAGL]], [[unitAimPosition]], [[unitAimPositionVisual]]
  
==PositionAGLS==
+
== PositionAGLS ==
  
 
:Over land, '''z''' is measured as height over terrain level minus the height of surface over terrain level underneath. If such surface exists and is counted in, the resulting '''z''' becomes 0. The following diagram illustrates how '''z''' is obtained for a soldier standing on a rock:
 
:Over land, '''z''' is measured as height over terrain level minus the height of surface over terrain level underneath. If such surface exists and is counted in, the resulting '''z''' becomes 0. The following diagram illustrates how '''z''' is obtained for a soldier standing on a rock:
Line 62: Line 63:
 
:Over sea it gets even more complicated as instead of [[PositionATL]], [[PositionASLW]] is used minus the offset for the surface height, presumably over waves too, as '''z''' seems static. As there is currently no way to obtain '''H''' of the surface, it becomes impossible to convert given [[PositionAGLS]] into other formats, unlike with other position formats.
 
:Over sea it gets even more complicated as instead of [[PositionATL]], [[PositionASLW]] is used minus the offset for the surface height, presumably over waves too, as '''z''' seems static. As there is currently no way to obtain '''H''' of the surface, it becomes impossible to convert given [[PositionAGLS]] into other formats, unlike with other position formats.
  
:<u>Related commands</u>:
+
:<u>Related commands:</u>
  
 
:[[position]], [[visiblePosition]], [[getPos]], [[getPosVisual]]
 
:[[position]], [[visiblePosition]], [[getPos]], [[getPosVisual]]
  
===setPosAGLS===
+
=== setPosAGLS ===
  
 
:The function below will place passed object onto walkable surface, if there is one, otherwise on the ground. If only '''x''' and '''y''' of the position are supplied, the object will be placed on surface, if '''z''' is supplied, it will be treated as offset from the surface level.
 
:The function below will place passed object onto walkable surface, if there is one, otherwise on the ground. If only '''x''' and '''y''' of the position are supplied, the object will be placed on surface, if '''z''' is supplied, it will be treated as offset from the surface level.
Line 80: Line 81:
 
_obj [[setPosASL]] _pos;
 
_obj [[setPosASL]] _pos;
 
};
 
};
//---This will place player exactly on top deck of Cargo HQ on Stratis:
+
</code>
<nowiki>[</nowiki>[[player]], [2437.18,5693.47,0]] [[call]] KK_fnc_setPosAGLS;
+
<code>{{codecomment|//---This will place player exactly on top deck of Cargo HQ on Stratis:}}
//---This will place player 2m above top deck of Cargo HQ on Stratis:
+
<nowiki>[</nowiki>[[player]], [2437.18,5693.47,0]] [[call]] KK_fnc_setPosAGLS;<br>
<nowiki>[</nowiki>[[player]], [2437.18,5693.47,2]] [[call]] KK_fnc_setPosAGLS;
+
{{codecomment|//---This will place player 2m above top deck of Cargo HQ on Stratis:}}
//---This will place player 2m below top deck of Cargo HQ on Stratis:
+
<nowiki>[</nowiki>[[player]], [2437.18,5693.47,2]] [[call]] KK_fnc_setPosAGLS;<br>
 +
{{codecomment|//---This will place player 2m below top deck of Cargo HQ on Stratis:}}
 
<nowiki>[</nowiki>[[player]], [2437.18,5693.47,-2]] [[call]] KK_fnc_setPosAGLS;</code>
 
<nowiki>[</nowiki>[[player]], [2437.18,5693.47,-2]] [[call]] KK_fnc_setPosAGLS;</code>
 
</blockquote>
 
</blockquote>
Line 90: Line 92:
 
:Alternatively, [[setVehiclePosition]] command can be used. It will put object onto nearest surface.  
 
:Alternatively, [[setVehiclePosition]] command can be used. It will put object onto nearest surface.  
 
<blockquote>
 
<blockquote>
<code>//---This will place player inside Cargo HQ on Stratis:
+
<code>{{codecomment|//---This will place player inside Cargo HQ on Stratis:}}
[[player]] [[setVehiclePosition]] <nowiki>[</nowiki>[2437.18,5693.47,0], [], 0, "CAN_COLLIDE"];
+
[[player]] [[setVehiclePosition]] <nowiki>[</nowiki>[2437.18,5693.47,0], [], 0, "CAN_COLLIDE"];<br>
//---This will place player on top deck of Cargo HQ on Stratis:
+
{{codecomment|//---This will place player on top deck of Cargo HQ on Stratis:}}
 
[[player]] [[setVehiclePosition]] <nowiki>[</nowiki>[2437.18,5693.47,100], [], 0, "CAN_COLLIDE"];</code>
 
[[player]] [[setVehiclePosition]] <nowiki>[</nowiki>[2437.18,5693.47,100], [], 0, "CAN_COLLIDE"];</code>
 
</blockquote>
 
</blockquote>
  
==PositionWorld==
+
== PositionWorld ==
  
 
:Similar to [[PositionASL]], however '''z''' is measured from the sea level to the the model centre [0,0,0] of an object, rather than transformed [[boundingCenter]] or land contact vertices.
 
:Similar to [[PositionASL]], however '''z''' is measured from the sea level to the the model centre [0,0,0] of an object, rather than transformed [[boundingCenter]] or land contact vertices.
 
<blockquote>
 
<blockquote>
 
+
<code>_identical = [[getPosWorld]] _obj [[isEqualTo]] [[AGLtoASL]] (_obj [[modelToWorld]] [0,0,0]); {{codecomment|// should be true}}</code>
<code>_identical = [[getPosWorld]] _obj [[isEqualTo]] [[AGLtoASL]] (_obj [[modelToWorld]] [0,0,0]); //should be true</code>
 
 
</blockquote>
 
</blockquote>
  
:<u>Related commands</u>:
+
:<u>Related commands:</u>
  
 
:[[getPosWorld]], [[setPosWorld]], [[mapCenterOnCamera]]
 
:[[getPosWorld]], [[setPosWorld]], [[mapCenterOnCamera]]
  
==PositionRelative==
+
== PositionRelative ==
  
 
:Relative position is normally an '''[x,y,z]''' offset from the model centre.
 
:Relative position is normally an '''[x,y,z]''' offset from the model centre.
  
:<u>Related commands</u>:
+
:<u>Related commands:</u>
  
 
:[[positionCameraToWorld]], [[selectionPosition]], [[attachTo]], [[modelToWorld]], [[worldToModel]], [[modelToWorldVisual]], [[worldToModelVisual]], [[camPrepareRelPos]], [[camSetRelPos]]
 
:[[positionCameraToWorld]], [[selectionPosition]], [[attachTo]], [[modelToWorld]], [[worldToModel]], [[modelToWorldVisual]], [[worldToModelVisual]], [[camPrepareRelPos]], [[camSetRelPos]]
  
==PositionConfig==
+
== PositionConfig ==
  
 
:The format used in configs, such as ''mission.sqm'', is '''[x,z,y]''', where '''z''' and '''y''' are swapped around. One other command that uses this format is [[positionCameraToWorld]]. '''z''' in configs is measured from the sea level.
 
:The format used in configs, such as ''mission.sqm'', is '''[x,z,y]''', where '''z''' and '''y''' are swapped around. One other command that uses this format is [[positionCameraToWorld]]. '''z''' in configs is measured from the sea level.
 +
 +
 +
[[Category: Scripting Topics]]

Revision as of 23:29, 30 August 2019

Introduction

Positions in Arma could be either 2D, in which case it is in format [x,y], where x is the coordinate on the WestEast axis and y is the coordinate on SouthNorth axis, or 3D, in which case it is in format [x,y,z], where z is the height. The height relative to exactly what differs depending on the format of 3D position used.

Since Arma 3 v1.93.145664 position values are limited to [-50km/+500km,-50km/+500km,-50km/+500km]

Formats

There are a number of formats available in the game:
  • ASL – Presumably “Above Sea Level”
  • ATL – Presumably “Above Terrain Level”
  • ASLW – Presumably “Above Sea Level inc. Waves”
  • AGL – Presumably “Above Generic/Ground Level”
  • AGLS – Presumably “Above Generic/Ground Level inc. Surfaces”
  • World – Raw world coordinate system
  • Relative – Position relative to an object within its model space
  • Config – Position used in configs
  • Object – When object is used for position, PositionWorld of the object is used
The following diagram illustrates some of the most used formats:
position.jpg

PositionASL

z is measured from the sea level which is constant across the map.
Related commands:
getPosASL, setPosASL, getPosASLVisual, visiblePositionASL, ASLToATL, ATLToASL, AGLToASL, ASLToAGL, eyePos, aimPos, getTerrainHeightASL, lineIntersects, lineIntersectsWith, lineIntersectsObjs, lineIntersectsSurfaces, terrainIntersectASL, playSound3D, setDefaultCamera

PositionASLW

z is measured from the surface of the sea that could be higher or lower than sea level due to waves.
Related commands:
getPosASLW, setPosASLW

PositionATL

z is measured from the terrain level which varies across the map.
Related commands:
getPosATL, setPosATL, getPosATLVisual, ASLToATL, ATLToASL

PositionAGL

z is the same as in PositionASLW when over sea and is the same as in PositionATL when over land. Most commands either take or return PositionAGL.
Related commands:
modelToWorld, worldToModel, modelToWorldVisual, worldToModelVisual, positionCameraToWorld, intersect, terrainIntersect, isOnRoad, drawIcon3D, drawLine3D, distance, moveTo, doMove, move, setDestination, buildingPos, screenToWorld, worldToScreen, AGLToASL, ASLToAGL, unitAimPosition, unitAimPositionVisual

PositionAGLS

Over land, z is measured as height over terrain level minus the height of surface over terrain level underneath. If such surface exists and is counted in, the resulting z becomes 0. The following diagram illustrates how z is obtained for a soldier standing on a rock:
z.jpg
Over sea it gets even more complicated as instead of PositionATL, PositionASLW is used minus the offset for the surface height, presumably over waves too, as z seems static. As there is currently no way to obtain H of the surface, it becomes impossible to convert given PositionAGLS into other formats, unlike with other position formats.
Related commands:
position, visiblePosition, getPos, getPosVisual

setPosAGLS

The function below will place passed object onto walkable surface, if there is one, otherwise on the ground. If only x and y of the position are supplied, the object will be placed on surface, if z is supplied, it will be treated as offset from the surface level.

KK_fnc_setPosAGLS = { params ["_obj", "_pos", "_offset"]; _offset = _pos select 2; if (isNil "_offset") then {_offset = 0}; _pos set [2, worldSize]; _obj setPosASL _pos; _pos set [2, vectorMagnitude (_pos vectorDiff getPosVisual _obj) + _offset]; _obj setPosASL _pos; }; //---This will place player exactly on top deck of Cargo HQ on Stratis: [player, [2437.18,5693.47,0]] call KK_fnc_setPosAGLS;
//---This will place player 2m above top deck of Cargo HQ on Stratis: [player, [2437.18,5693.47,2]] call KK_fnc_setPosAGLS;
//---This will place player 2m below top deck of Cargo HQ on Stratis: [player, [2437.18,5693.47,-2]] call KK_fnc_setPosAGLS;

Alternatively, setVehiclePosition command can be used. It will put object onto nearest surface.

//---This will place player inside Cargo HQ on Stratis: player setVehiclePosition [[2437.18,5693.47,0], [], 0, "CAN_COLLIDE"];
//---This will place player on top deck of Cargo HQ on Stratis: player setVehiclePosition [[2437.18,5693.47,100], [], 0, "CAN_COLLIDE"];

PositionWorld

Similar to PositionASL, however z is measured from the sea level to the the model centre [0,0,0] of an object, rather than transformed boundingCenter or land contact vertices.

_identical = getPosWorld _obj isEqualTo AGLtoASL (_obj modelToWorld [0,0,0]); // should be true

Related commands:
getPosWorld, setPosWorld, mapCenterOnCamera

PositionRelative

Relative position is normally an [x,y,z] offset from the model centre.
Related commands:
positionCameraToWorld, selectionPosition, attachTo, modelToWorld, worldToModel, modelToWorldVisual, worldToModelVisual, camPrepareRelPos, camSetRelPos

PositionConfig

The format used in configs, such as mission.sqm, is [x,z,y], where z and y are swapped around. One other command that uses this format is positionCameraToWorld. z in configs is measured from the sea level.