Home   Help Search Login Register  

Author Topic: vertical axis  (Read 719 times)

0 Members and 1 Guest are viewing this topic.

Aeon

  • Guest
vertical axis
« 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 ?

CareyBear

  • Guest
Re:vertical axis
« Reply #1 on: 02 Nov 2002, 06:28:06 »
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:
Quote
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
  • )*2)-1);

if (format ["%1", _elevation] == {-1.#IND}) then {_elevation = 0};
_elevation

Cheers,

CareyBear