dragonsyr 21 Posted December 10, 2013 (edited) i have an object as reference for direction (placed facing west in my case (in the middle and verticaly from airport runway) i need a script that checks the player relative position from target relative direction, (im confused a little about this) so if the player is 0-180 from object direction then must go for north approach and if 180-360 then go for south approach (something like that) i need something like that i think _targetdir = getdir _target; // return direction of the object ???? or this _targetdir = direction _target _playerPos = [_targetdir, player] call BIS_fnc_relativeDirTo; // Check the direction of the player relative to the _target direction??? if (_playerPos = 0 to 180 from _targetdir) then {hint "you are right of the object";}; //??? if (_playerPos =180 to 360 from _targetdir) then {hint "you are left of the object";}; //??? Edited December 10, 2013 by dragonsyr Share this post Link to post Share on other sites
Mattar_Tharkari 10 Posted December 10, 2013 (edited) if (_playerPos < 180) then {hint "you are right of the object";} else {hint "you are left of the object";}; BIS_fnc_relativeDirTo returns 0 - 360 so thats all you need I think? Edited December 10, 2013 by Mattar_Tharkari Share this post Link to post Share on other sites
dragonsyr 21 Posted December 10, 2013 first of all , the code that i post is not working . its a code from my head. i need if the player is 0-180 from the object direction ,then something if 180-359 from object direction then something else i prefer command between 2 specific numbers and not <180 (0-60 or 70-90 0-179 etc......... for future use with other things also) thnks for the reply ---------- Post added at 18:35 ---------- Previous post was at 18:25 ---------- _targetdir = getdir _target; // return direction of the object ???? or this _targetdir = direction _target _playerPos = [_targetdir, player] call BIS_fnc_relativeDirTo; // Check the direction of the player relative to the _target direction??? if (_playerPos = 0 to 90 from _targetdir) then {hint "you are right front of the object";}; //??? if (_playerPos = 90 to 180 from _targetdir) then {hint "you are right and behind of the object";}; //??? if (_playerPos =180 to 360 from _targetdir) then {hint "you are left of the object";}; //??? to see the diference between 2 numbers Share this post Link to post Share on other sites
Larrow 2823 Posted December 10, 2013 if (_playerPos > 0 && _playerPos < 180 ) then { .... Share this post Link to post Share on other sites
dragonsyr 21 Posted December 10, 2013 if i use this _target = relpos; //name of object _targetdir = getdir _target; // return direction of the object ???? or this _targetdir = direction _target _playerPos = [_targetdir, player] call BIS_fnc_relativeDirTo; if (_playerPos > 0 && _playerPos < 180 ) then {hint "you are right of the object";}; if (_playerPos >181 && _playerPos < 360 ) then {hint "you are left of the object";}; i get _ret = ((_pos2 select 0) - (_pos1 select 0)) atan2 ((_pos2 select 1) - (_p> Error position: <select 0)) atan2 ((_pos2 select 1) - (_p> Error select: Type Number, expected Array,Config entry File A3\functions_f\geometry\fn_dirTo.sqf, line 24 Share this post Link to post Share on other sites
Larrow 2823 Posted December 10, 2013 relativeDirTo expects either OBJECT or POSITIONS [x,y,z] as parameters, you are passing it _targetdir which is a NUMBER, just pass it _target instead. _playerPos = [player, relPos] call BIS_fnc_relativeDirTo; if (_playerPos >= 0 && _playerPos <= 179 ) then {hint "you are right of the object";}; if (_playerPos >= 180 && _playerPos <= 360 ) then {hint "you are left of the object";}; Share this post Link to post Share on other sites
Mattar_Tharkari 10 Posted December 10, 2013 ninja'd you are giving the function a peram it doesn't take - needs to be objects or positions not a direction scriptName "Functions\geometry\fn_relativeDirTo.sqf"; /************************************************************ Relative Direction To By Andrew Barron Parameters: [object 1, object or position 2] Returns the relative direction from object 1 to object/position 2. Return is always 0-360. A position to the right of unit would be at a relative direction of 90 degrees, for example. Example: [player, getpos dude] call BIS_fnc_relativeDirTo ************************************************************/ private "_dir"; _dir = _this call BIS_fnc_dirTo; //get direction to target _dir = _dir - (getdir (_this select 0)); //subtract direction of unit //ensure return is between 0-360 if (_dir < 0) then {_dir = _dir + 360}; if (_dir > 360) then {_dir = _dir - 360}; _dir Share this post Link to post Share on other sites
dragonsyr 21 Posted December 10, 2013 (edited) ---------- Post added at 20:25 ---------- Previous post was at 20:23 ---------- i want to make it more clear to you, because my english is bad.... im the player , you are the object and you facing west. i want ,when i m to your relative direction from 45 to 125 , then i get {hint"you r right of the object";}; 126 to 235 then {hint"you r behind of the object";}; etc... i dont know how can tell you other way sorry for that Edited December 10, 2013 by dragonsyr Share this post Link to post Share on other sites
Larrow 2823 Posted December 10, 2013 OK i understand what your saying, open a new map, place this in the players init, in game use the action to change the arrow direction... h = [] spawn { arrow = "Sign_Arrow_Direction_F" createVehicle ( [(getPosATL player), 5, getDir player] call BIS_fnc_relPos ); arrow setDir 270; player addAction ["Arrow Rand Dir", {arrow setDir (random 360) }]; while {true} do { _target = arrow; { _relDir = [_target, player] call BIS_fnc_relativeDirTo; if ( _relDir > (_x select 0) && _relDir < (_x select 1) ) then { hintSilent format["Player is %1 the target",(_x select 2)]; }; }forEach [ [45, 135, "to the right of"], [135, 225, "behind"], [225, 315, "to the left of"], [315, 360, "infront"], [0, 45, "infront"] ]; }; }; The bit your interested in is ... _target = arrow; { _relDir = [_target, player] call BIS_fnc_relativeDirTo; if ( _relDir > (_x select 0) && _relDir < (_x select 1) ) then { hintSilent format["Player is %1 the target",(_x select 2)]; }; }forEach [ [45, 135, "to the right of"], [135, 225, "behind"], [225, 315, "to the left of"], [315, 360, "infront"], [0, 45, "infront"] ]; Everything else is just for the demo. Share this post Link to post Share on other sites
dragonsyr 21 Posted December 10, 2013 thank you very much Larrow... i will try this asap......thank all of you for the time who spend for my demands :-))) Share this post Link to post Share on other sites
dragonsyr 21 Posted December 10, 2013 working as i need... thank you sir! Share this post Link to post Share on other sites
dragonsyr 21 Posted December 13, 2013 (edited) i convert your code for my needs but i have a problem if i use this _target = rwdir; //my object _relDir = [_target, player] call BIS_fnc_relativeDirTo; if ( _relDir > 0 && _relDir < 180 ) then {hint"you are right";sleep 1;}; if ( _relDir > 180 && _relDir < 360 ) then {hint"you are left";sleep 1;}; working from 0-180 as right and 180- almost 200 as left. from 200 to 360 nothing happend. if i use this _target = rwdir; //my object _relDir = [_target, player] call BIS_fnc_relativeDirTo; if ( _relDir > 0 && _relDir < 180 ) then {hint"you are right";sleep 1;} else{hint"you are left";sleep 1;}; //if ( _relDir > 180 && _relDir < 360 ) then {hint"you are left";sleep 1;};}; working . why the first commands working this way???? i m doing something wrong???? Edited December 13, 2013 by dragonsyr Share this post Link to post Share on other sites
xendance 3 Posted December 13, 2013 Why not just use if else block instead of two ifs. If you aren't on right, you can only be on the left. Though in the most extreme cases you could be straight ahead, but I'd disregard that possibility ;) Edit: Also the first one works fine on my end. Share this post Link to post Share on other sites
dragonsyr 21 Posted December 13, 2013 (edited) note: the hint "left",right" i use is for debug only..... just for the tests......when the code working i replace the hint..... ---------- Post added at 18:14 ---------- Previous post was at 18:10 ---------- i want to solve this because i want to use in future scripts this _target = rwdir; _relDir = [_target, player] call BIS_fnc_relativeDirTo; if ( _relDir > 0 && _relDir < 90 ) then {hint"you are frontright";sleep 1;}; if ( _relDir > 90 && _relDir < 180 ) then {hint"you are backright";sleep 1;}; if ( _relDir > 180 && _relDir < 270 ) then {hint"you are backleft";sleep 1;}; and this is the problem ...... i tried with "or" instead of "&&" but with this i have other problems (2 hints mixed together) ---------- Post added at 18:19 ---------- Previous post was at 18:14 ---------- Edit: Also the first one works fine on my end. not working for me ... i have problem from around 200 to 360......no hint at all ---------- Post added at 18:24 ---------- Previous post was at 18:19 ---------- i think is something between the first if <180 and the second if <360 .... i dont know..... i m confused ---------- Post added at 18:53 ---------- Previous post was at 18:24 ---------- i test this _target = rwdir; _relDir = [_target, player] call BIS_fnc_relativeDirTo; if ( _relDir > 0 && _relDir < 90 ) then {hint"you are frontright";sleep 1;}; if ( _relDir > 90 && _relDir < 180 ) then {hint"you are backright";sleep 1;}; if ( _relDir > 180 && _relDir < 270 ) then {hint"you are backleft";sleep 1;}; if ( _relDir > 270 && _relDir < 359 ) then {hint"you are frontleft";sleep 1;}; // also this if ( _relDir > 270 ) then {hint"you are frontleft";sleep 1;}; and works only the 3 ifs from 0 to 270. after that no hint for frontleft this is strange... Edited December 13, 2013 by dragonsyr Share this post Link to post Share on other sites
xendance 3 Posted December 13, 2013 note: the hint "left",right" i use is for debug only..... just for the tests......when the code working i replace the hint.....---------- Post added at 18:14 ---------- Previous post was at 18:10 ---------- i want to solve this because i want to use in future scripts this _target = rwdir; _relDir = [_target, player] call BIS_fnc_relativeDirTo; if ( _relDir > 0 && _relDir < 90 ) then {hint"you are frontright";sleep 1;}; if ( _relDir > 90 && _relDir < 180 ) then {hint"you are backright";sleep 1;}; if ( _relDir > 180 && _relDir < 270 ) then {hint"you are backleft";sleep 1;}; and this is the problem ...... i tried with "or" instead of "&&" but with this i have other problems (2 hints mixed together) ---------- Post added at 18:19 ---------- Previous post was at 18:14 ---------- not working for me ... i have problem from around 200 to 360......no hint at all ---------- Post added at 18:24 ---------- Previous post was at 18:19 ---------- i think is something between the first if <180 and the second if <360 .... i dont know..... i m confused ---------- Post added at 18:53 ---------- Previous post was at 18:24 ---------- i test this _target = rwdir; _relDir = [_target, player] call BIS_fnc_relativeDirTo; if ( _relDir > 0 && _relDir < 90 ) then {hint"you are frontright";sleep 1;}; if ( _relDir > 90 && _relDir < 180 ) then {hint"you are backright";sleep 1;}; if ( _relDir > 180 && _relDir < 270 ) then {hint"you are backleft";sleep 1;}; if ( _relDir > 270 && _relDir < 359 ) then {hint"you are frontleft";sleep 1;}; and works only the 3 ifs from 0 to 270. after that no hint for frontleft this is strange... What is the rwDir variable? Is it a position or an object? Share this post Link to post Share on other sites
dragonsyr 21 Posted December 13, 2013 (edited) name of object in map the object is a "Sign_Arrow_Direction_F" only for the tests edit : copy from my mission class Item11 { position[]={1705.1261,5.5,5465.5557}; azimut=285; id=19; side="EMPTY"; vehicle="Sign_Arrow_Direction_F"; skill=0.60000002; text="rwdir"; }; edit: with this works .......but when i m on position 0-270 then i get the true position and after i get the else from the last if in the code........... _target = rwdir; _relDir = [_target, player] call BIS_fnc_relativeDirTo; if ( _relDir > 0 && _relDir < 90 ) then {hint"you are frontright";sleep 1;}; if ( _relDir > 90 && _relDir < 180 ) then {hint"you are backright";sleep 1;}; if ( _relDir > 180 && _relDir < 270 ) then {hint"you are backleft";sleep 1;} else {hint"you are frontleft";sleep 1;}; //if ( _relDir > 270 && _relDir < 359 ) then {hint"you are frontleft";sleep 1;}; ---------- Post added at 19:39 ---------- Previous post was at 19:16 ---------- i tried only this _target = rwdir; _relDir = [_target, player] call BIS_fnc_relativeDirTo; if ( _relDir > 270 && _relDir < 359 ) then {hint"you are frontleft";sleep 1;} else {hint"you are nowhere";sleep 1;}; the only hint i get all around object is ...... guess what!! you are nowhere !!!! the 270-360 not working Edited December 13, 2013 by dragonsyr Share this post Link to post Share on other sites
Larrow 2823 Posted December 13, 2013 (edited) and works only the 3 ifs from 0 to 270. If i put a direction arrow in the map called rwdir, and place this straight in the debug console , which is just a copy and paste of your code above I have no problems all hint display correctly !! terminate h; h = [] spawn { while {true} do { _target = rwdir; _relDir = [_target, player] call BIS_fnc_relativeDirTo; if ( _relDir > 0 && _relDir < 90 ) then { hint"you are frontright"; sleep 1; }; if ( _relDir > 90 && _relDir < 180 ) then { hint"you are backright"; sleep 1; }; if ( _relDir > 180 && _relDir < 270 ) then { hint"you are backleft"; sleep 1; }; if ( _relDir > 270 && _relDir < 359 ) then { hint"you are frontleft"; sleep 1; }; }; }; Any chance you can post a test mission showing your error? EDIT: test mission - above script run from init.sqf, just player and direction arrow in map. Edited December 13, 2013 by Larrow 1 Share this post Link to post Share on other sites
dragonsyr 21 Posted December 13, 2013 i tried excactly the above code and no frontleft for me. Share this post Link to post Share on other sites
Sniperwolf572 758 Posted December 13, 2013 (edited) If i put a direction arrow in the map called rwdir, and place this straight in the debug console , which is just a copy and paste of your code above I have no problems all hint display correctly !! terminate h; h = [] spawn { while {true} do { _target = rwdir; _relDir = [_target, player] call BIS_fnc_relativeDirTo; if ( _relDir > 0 && _relDir < 90 ) then { hint"you are frontright"; sleep 1; }; if ( _relDir > 90 && _relDir < 180 ) then { hint"you are backright"; sleep 1; }; if ( _relDir > 180 && _relDir < 270 ) then { hint"you are backleft"; sleep 1; }; if ( _relDir > 270 && _relDir < 359 ) then { hint"you are frontleft"; sleep 1; }; }; }; Any chance you can post a test mission showing your error? EDIT: test mission - above script from init.sqf init.sqf, just player and direction arrow in map. Just a note that none of these conditions will trigger if you are at exactly 0, 90, 180, 270 or 359 degrees. You need to either use higher-or-equal-to operator (>=) on the left side or lower-or-equal-to operator (<=) on the right side (but not both!) so it includes those degrees as well. If you are having problems, I suggest hinting the value of _relDir as well, so you know what _relDir is and why it isn't matching any conditions. hint format ["_relDir is %1", _relDir]; I also suggest moving the sleeps into a single slee outside the if conditions, on the same level as _relDir, but after the conditions, so you don't have to write it 4 times, but instead only once. Edited December 13, 2013 by Sniperwolf572 Share this post Link to post Share on other sites
dragonsyr 21 Posted December 13, 2013 i make new empty mission only with the arrow and a unit as player. same thing......no frontleft ... wtf??? cbaa3 and mcc mod only...... Share this post Link to post Share on other sites
Larrow 2823 Posted December 13, 2013 (edited) Just to show im not trying to wind you up heres a video VIDEO (crap quality to keep size down but shows it working from scratch) Yer realise all that sniperwolf but its more just figuring out whats going on with dragonsyr at the moment rather than finessing the script Edited December 13, 2013 by Larrow Share this post Link to post Share on other sites
Sniperwolf572 758 Posted December 13, 2013 Just to show im not trying to wind you up heres a video VIDEO (crap quality to keep size down but shows it working from scratch)Yer realise all that sniperwolf but its more just figuring out whats going on with dragonsyr at the moment rather than finessing the script Ok. Just tried it in editor. Relative dir returns a negative value for some objects. For this car, the range is -180 to 180. For this arrow, it's 0 to 360. Share this post Link to post Share on other sites
dragonsyr 21 Posted December 13, 2013 If you are having problems, I suggest hinting the value of _relDir as well, so you know what _relDir is and why it isn't matching any conditions. hint format ["_relDir is %1", _relDir]; . i try with this and after 253 degrees i get nothing...... Share this post Link to post Share on other sites
Larrow 2823 Posted December 13, 2013 Ok. Just tried it in editor. Relative dir returns a negative value for some objects. lol how can that be :/ the last two lines of bis_fnc_relativedirto are //ensure return is between 0-360 if (_dir < 0) then {_dir = _dir + 360}; if (_dir > 360) then {_dir = _dir - 360}; Share this post Link to post Share on other sites
dragonsyr 21 Posted December 13, 2013 @ Larrow .....maybe this is stupid.....but can you set the azimouth in your arrow to 285 degrees? Share this post Link to post Share on other sites