getPos: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
m (Text replacement - "<sqf>([^↵][^\/]*↵[^\/]*)<\/sqf>" to "<sqf> $1 </sqf>")
 
(115 intermediate revisions by 14 users not shown)
Line 1: Line 1:
{{Command|= Comments
{{RV|type=command
____________________________________________________________________________________________


| ofp |= Game name
|game1= ofp
|version1= 1.00


|1.00|= Game version
|game2= ofpe
|version2= 1.00


|arg= global |= Arguments in MP
|game3= arma1
____________________________________________________________________________________________
|version3= 1.00


| Returns the object position in format [[Position]].  |= Description
|game4= arma2
____________________________________________________________________________________________
|version4= 1.00


| [[Array]] <nowiki>=</nowiki> '''getPos''' object |= Syntax
|game5= arma2oa
|p1 = object: [[Object]]; since VBS2 1.24: [[Location]]
|version5= 1.50
| [[Array]] - format [[Position]] |= Return value
____________________________________________________________________________________________
|x1 = <code>'''getPos''' [[player]] </code>
| [[position]], [[getPosASL]], [[getPosATL]], [[getMarkerPos]], [[setPos]] |= See also


|game6= tkoh
|version6= 1.00
|game7= arma3
|version7= 0.50
|arg= global
|gr1= Positions
|descr= Returns object or location position. If the argument is an object, the return value is in format [[Position#PositionAGLS|PositionAGLS]].<br>
The alternative syntax gets the position given distance and heading away from provided object or position - the command equivalent of [[BIS_fnc_relPos]].
{{Feature|important|
Do '''not''' use this command to get an object's position in 3D format:
* the Z value from this command is '''relative''' to the surface underneath, and there is no compatible setter command to use it with;<br>the commonly misused code: <sqf inline>_obj1 setPos getPos _obj2</sqf> is '''absolutely wrong'''
* this command is significantly '''slower''' than other [[:Category:Command Group: Positions|position commands]] because it has to calculate the surface below a position from objects in the (2D) area; its performance therefore suffers from areas with a high density of objects such as cities, and can easily be ~20x slower than other, simpler position commands - see [[Code Optimisation#getPos.2A and setPos.2A|this benchmark]].
The '''only''' correct usage of this command is to determine the altitude of an object '''from the surface below it''' (see {{Link|#Example 5}}).
}}
}}
|s1= [[getPos]] object
|p1= object: [[Object]]


<h3 style="display:none">Notes</h3>
|r1= [[Array]] format [[Position#PositionAGLS|PositionAGLS]] - where Z is the height over the surface underneath
<dl class="command_description">
<!-- Note Section BEGIN -->
<dd class="notedate">Posted on 16 Feb, 2007
<dt class="note">'''[[User:Dr_Eyeball|Dr_Eyeball]]'''<dd class="note">
getPos obj select 2
might return the vertical position above ground level, but for a stacked object, it returns the vertical position above the object beneath it. The same problem exists for [[getPosASL]]. There was a [http://www.flashpoint1985.com/cgi-bin/ikonboard311/ikonboard.cgi?s=e587356595b907e91f96b8817d7f8a26;act=ST;f=71;t=57918 discussion] thread in the BIS forums which suggested the use of the command [[modelToWorld]] instead to get around this issue where an absolute vertical position is required. ArmA Ver '''1.02'''.


<dd class="notedate">Posted on 14 Dec, 2010
|s2= [[getPos]] location
<dt class="note">'''[[User:disat|disat]]'''<dd class="note">
This command returns a [[PositionAGL]].  Apparently, [[Position]] and [[PositionAGL]] are the same thing.


<dd class="notedate">Posted on 6 Feb, 2011
|p21= location: [[Location]]
<dt class="note">'''[[User:Hduregger|Hduregger]]'''<dd class="note">
The z height returned changes dynamically with the height of waves beneath the object, if the object is located over sea. The z height returned by [[getPosATL]] and [[getPosASL]] does not change like this. This was tested by continuously retrieving the position of a static object, like the cross in the empty/corpses category, placed over sea or land.
[[getPos]] behaves similar to
_obj modelToWorld [0.0, 0.0, 0.0]
but it does not give the same result, therefore
(_obj modelToWorld [0.0, 0.0, 0.0]) != (getPos _obj).


<dd class="notedate">Posted on 23 Nov, 2011
|r2= [[Array]] format [[Position#PositionAGL|PositionAGL]] - see [[locationPosition]]
<dt class="note">'''[[User:Tankbuster|Tankbuster]]'''<dd class="note">
You can use getPos and setPos on triggers.


<!-- Note Section END -->
|s3= origin [[getPos]] [distance, heading]
</dl>


<h3 style="display:none">Bottom Section</h3>
|s3since= arma3 1.56
[[Category:Scripting Commands|GETPOS]]
 
[[Category:Scripting Commands OFP 1.96|GETPOS]]
|p41= origin: [[Object]], [[Position#Introduction|Position2D]] or [[Position#Introduction|Position3D]]
[[Category:Scripting Commands OFP 1.46|GETPOS]]
 
[[Category:Scripting Commands ArmA|GETPOS]]
|p42= distance: [[Number]] - distance from position
[[Category:Command_Group:_Object_Information|{{uc:{{PAGENAME}}}}]]
 
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
|p43= heading: [[Number]] - in which compass direction
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]
 
|r3= [[Array]] format [[Position#PositionAGL|PositionAGL]]
 
|x1= <sqf>hintSilent str getPos player;</sqf>
 
|x2= [[getPos]] vs. other methods (over sea). Pay attention to Z values:
<sqf>
getPos ship; // [2412.01, 6036.33, -0.839965]
getPosATL ship; // [2412.01, 6036.33, 19.4266]
getPosASL ship; // [2412.01, 6036.33, -0.920066]
getPosASLW ship; // [2412.01, 6036.33, -0.865981]
visiblePosition ship; // [2412.02, 6036.33, -0.837952]
visiblePositionASL ship; // [2412.02, 6036.33, -0.91798]
position ship; // [2412.01, 6036.33, -0.839965]
</sqf>
 
|x3= [[getPos]] vs. other methods (over land, on top of a 100m high building). Pay attention to Z values:
<sqf>
getPos car; // [2508.64, 5681.47, 0.0609589]
getPosATL car; // [2508.64, 5681.47, 100.0356369]
getPosASL car; // [2508.64, 5681.47, 171.718]
getPosASLW car; // [2508.64, 5681.47, 171.718]
visiblePosition car; // [2508.64, 5681.47, 0.0609512]
visiblePositionASL car; // [2508.64, 5681.47, 171.718]
position car; // [2508.64, 5681.47, 0.0609589]
</sqf>
 
|x4= Find position 100 metres and 45 degrees from player position:
<sqf>player getPos [100, 45];</sqf>
 
|x5= Determine if a free-falling unit is close enough to the surface (including buildings, aircraft carriers etc) below to deploy the parachute:
<sqf>
waitUntil { sleep 1; getPos player select 2 < 200 };
hint "Deploying a parachute might be a good idea";
</sqf>
 
|seealso= [[getPosVisual]] [[getRelPos]] [[setPos]] [[Position#setPosAGLS|setPosAGLS]] [[position]] [[getPosATL]] [[getPosASL]] [[getPosASLW]] [[visiblePosition]] [[visiblePositionASL]] [[getMarkerPos]]
}}
 
{{Note
|user= Dr_Eyeball
|timestamp= 20070217134300
|text= <sqf inline>getPos obj select 2</sqf> might return the vertical position above ground level, but for a stacked object, it returns the vertical position above the object beneath it. The same problem existed for [[getPosASL]] ('''pre-Arma 2 games only'''). There was a {{Link|link= http://www.flashpoint1985.com/cgi-bin/ikonboard311/ikonboard.cgi?s=e587356595b907e91f96b8817d7f8a26;act=ST;f=71;t=57918|text= discussion}} thread in the BIS forums which suggested the use of the command [[modelToWorld]] instead to get around this issue where an absolute vertical position is required. ArmA Ver '''1.02'''.
}}

Latest revision as of 11:34, 3 September 2024

Hover & click on the images for description

Description

Description:
Returns object or location position. If the argument is an object, the return value is in format PositionAGLS.
The alternative syntax gets the position given distance and heading away from provided object or position - the command equivalent of BIS_fnc_relPos.
Do not use this command to get an object's position in 3D format:
  • the Z value from this command is relative to the surface underneath, and there is no compatible setter command to use it with;
    the commonly misused code: _obj1 setPos getPos _obj2 is absolutely wrong
  • this command is significantly slower than other position commands because it has to calculate the surface below a position from objects in the (2D) area; its performance therefore suffers from areas with a high density of objects such as cities, and can easily be ~20x slower than other, simpler position commands - see this benchmark.
The only correct usage of this command is to determine the altitude of an object from the surface below it (see Example 5).
Groups:
Positions

Syntax 1

Syntax:
getPos object
Parameters:
object: Object
Return Value:
Array format PositionAGLS - where Z is the height over the surface underneath

Syntax 2

Syntax:
getPos location
Parameters:
location: Location
Return Value:
Array format PositionAGL - see locationPosition

Syntax 3

Syntax:
origin getPos [distance, heading]
Parameters:
origin: Object, Position2D or Position3D
distance: Number - distance from position
heading: Number - in which compass direction
Return Value:
Array format PositionAGL

Examples

Example 1:
Example 2:
getPos vs. other methods (over sea). Pay attention to Z values:
getPos ship; // [2412.01, 6036.33, -0.839965] getPosATL ship; // [2412.01, 6036.33, 19.4266] getPosASL ship; // [2412.01, 6036.33, -0.920066] getPosASLW ship; // [2412.01, 6036.33, -0.865981] visiblePosition ship; // [2412.02, 6036.33, -0.837952] visiblePositionASL ship; // [2412.02, 6036.33, -0.91798] position ship; // [2412.01, 6036.33, -0.839965]
Example 3:
getPos vs. other methods (over land, on top of a 100m high building). Pay attention to Z values:
getPos car; // [2508.64, 5681.47, 0.0609589] getPosATL car; // [2508.64, 5681.47, 100.0356369] getPosASL car; // [2508.64, 5681.47, 171.718] getPosASLW car; // [2508.64, 5681.47, 171.718] visiblePosition car; // [2508.64, 5681.47, 0.0609512] visiblePositionASL car; // [2508.64, 5681.47, 171.718] position car; // [2508.64, 5681.47, 0.0609589]
Example 4:
Find position 100 metres and 45 degrees from player position:
player getPos [100, 45];
Example 5:
Determine if a free-falling unit is close enough to the surface (including buildings, aircraft carriers etc) below to deploy the parachute:
waitUntil { sleep 1; getPos player select 2 < 200 }; hint "Deploying a parachute might be a good idea";

Additional Information

See also:
getPosVisual getRelPos setPos setPosAGLS position getPosATL getPosASL getPosASLW visiblePosition visiblePositionASL getMarkerPos

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Dr_Eyeball - c
Posted on Feb 17, 2007 - 13:43 (UTC)
getPos obj select 2 might return the vertical position above ground level, but for a stacked object, it returns the vertical position above the object beneath it. The same problem existed for getPosASL (pre-Arma 2 games only). There was a discussion (dead link) thread in the BIS forums which suggested the use of the command modelToWorld instead to get around this issue where an absolute vertical position is required. ArmA Ver 1.02.