OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Aeon on 30 Oct 2002, 00:26:30
-
With getdir/setdir we can work horizontal axis for scripting, I would know if there is a way to find and exploit vertical axis. How could we know if a unit aiming top or bottom target ?
-
Ok.. Dinger of the famously complicated scripting solutions has just asked me to post his solution to a very similar problem for you. ;)
There is no way to actually find the current target of a unit (as far as I know), but you can use the following little sqf to find the elevation to a target from a particular unit (let's call it aP).
First, create a game logic called myGameLogic
Next find the heading from aP to target using the following trig:
heading = (getpos target select 0) - (getpos point select 0) atan2 (getpos target select 1) - (getpos point select 1)
The elevation sqf is called by the following line:
elevation = [object, direction, distance] call loadfile "elevation.sqf"
And the elevation.sqf file is as follows:
private [{_subject}, {_direction}, {_range}, {_distance}, {_elevation}];
_subject = _this select 0;
_direction = _this select 1;
_range = _this select 2;
myGameLogic setpos [(getpos _subject select 0)+ (_range * (sin _direction)), (getpos _subject select 1)+ (_range * (cos _direction)), 0];
_distance = _subject distance myGameLogic;
myGameLogic setpos [getpos myGameLogic select 0, getpos myGameLogic select 1, sqrt ((_distance ^2)-(_range^2))];
_elevation = (acos (_range/_distance))*((({myGameLogic distance _subject > _distance} count
if (format ["%1", _elevation] == {-1.#IND}) then {_elevation = 0};
_elevation
Cheers,
CareyBear