Jump to content
Sign in to follow this  
panther42

Problem with Bis_fnc_dirTo

Recommended Posts

I'm trying to use BIS_fnc_DirTo, but am having problems with it giving me negative values...

Calling the function like this:

_align1 = (_aligns select 0);

_target setPosASL _align1;

_heading = [_plane, _target] call BIS_fnc_dirTo;
_dist = _plane distance _target;

[side _pilot,"base"] sidechat format["%1 first landing position follow heading %2 degs, distance %3 meters", _plane, _heading, _dist];

Most of the time it works fine, giving me positive heading values, but I get alot of negative values like this:

bisfncdirto.jpg

Functions module is on the map, waituntil {!isnil "bis_fnc_init"}; is in my init...

Any suggestions? I thought BIS_fnc_dirTo was supposed to give only positive values between 0 and 360...

Share this post


Link to post
Share on other sites

Indeed, seems, that something is wrong with used in function code, that should ensure positive values. Maybe became obsolete? I don't know, anyway remedy is simple. Add this code:

if (_heading < 0) then {_heading = _heading + 360};

or even not use function at all and do this simple calculation yourself:

_align1 = (_aligns select 0);

_target setPosASL _align1;

_p1 = getPos _plane;
_p2 = getPos _target;

_dx = (_p2 select 0) - (_p1 select 0);
_dy = (_p2 select 1) - (_p1 select 1);

_heading = _dx atan2 _dy;
if (_heading < 0) then {_heading = _heading + 360};
_dist = _plane distance _target;

[side _pilot,"base"] sidechat format["%1 first landing position follow heading %2 degs, distance %3 meters", _plane, _heading, _dist];  

Share this post


Link to post
Share on other sites

Thanks Rydygier, I had found DirToPos function by snYpir on OFPEC, which checks if (_dir < 0) then { _dir = _dir + 360 }; and was going to use this one instead.

I just need to add:

if(typename _pos1 == "OBJECT") then {_pos1 = getpos _pos1};

if(typename _pos2 == "OBJECT") then {_pos2 = getpos _pos2};

so I can use objects or positions.

The BIS function checks:

_ret = _ret % 360; //ensure return is 0-360, but apparently isn't working correctly???

Thanks again

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×