OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Luke on 13 Aug 2008, 02:30:09
-
How does one find the vertical angle at which a static gun is pointing?
Luke
-
By calculating from the weaponDirection (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=w#816) vector? :dunno:
You can get the weapon direction of, say, the static M2 with
mgname weaponDirection "M2"
-
The horizontal angle is the azimuth (0 = north) and the vertical angle is the elevation (0 = horizontal):
_vector = mgname weaponDirection "M2";
_horizontalAngle = (_vector select 0) atan2 (_vector select 1); // Range: -180 to 180
_azimuth = ((_horizontalAngle + 360) mod 360); // Range: 0 to 360
_elevation = (_vector select 2) atan2 (sqrt(((_vector select 0) ^ 2) + ((_vector select 1) ^ 2)));
-
OK thanx.
However what's the difference between azimuth and elevation.
also
wouldn't (_horizontalangle + 360) mod 360 just equal _horizontalAngle anyway?
-
The horizontal angle is the azimuth, which is the number of degrees clockwise from North (0 = North; 90 = East, 180 = South, 270 = West) and the vertical angle is the elevation above the horizontal (0 = horizontal; +90 is up; -90 is down). I can't make it clearer than that!
_horizontalAngle, in my algorithm, is given in a range of -180 to 180, which is the normal mathematical way to show the angle, but not the way angles are normally shown in game or, for that matter, by the military. Normally, directions in ArmA are 0 to 360, such as the result from getDir, so that last line will convert it to a proper azimuth value for consistency. The "horizontal angle" and azimuth can be used interchangably in, say, setDir.
-
here is the code i use on my artillery mod, it might help you.
while {( ( vehicle player ) == ( vehicle _LRM119 ) ) } do
{
_tangent = ( ( vehicle player weaponDirection "LRM119" ) select 0 ) atan2 ( ( ( vehicle player weaponDirection "LRM119" ) ) select 1 );
_elevation = asin( ( vehicle player weaponDirection "LRM119" ) select 2 ) - asin( vectorDir vehicle player select 2 );
if ( _tangent < 0 ) then
{
_tangent = _tangent + 360
};
hint format[ "Tanget: %1\nElevation: %2", _tangent, _elevation];
Sleep 0.2;
};
If you want to display it in mils then you can add this
if ( _tangent < 0 ) then
{
_tangent = _tangent + 360
};
_tangent = _tangent * 17.777777777777777777777777777778;
_tangent = _tangent - (_tangent mod 1);
Just change the _tangent to _elevation and it will be converted to mills (mils are the 360 degree range expressed in increments from 0 to 6400) the ( _tangent mod 1); is just to round it down to the nearest 1 to eleminate decimals. if you want decimals remove that