Cloughy 0 Posted June 12, 2007 Would the following formula work in an Arma script, i noticed commas in the extression. _dir =mod(atan2(sin(_lon2-_lon1)*cos(_lat2),cos(_lat1)*sin(_lat2)-sin(_lat1)*cos(_lat2)*cos(_lon 2-_lon1)),2*pi) I want to calculate the direction needed from point1 (units loc) and point2 (target.) I need the dir for the setDir command cause i want unit to face the target, cause im using the carmover script. Cheers GC Share this post Link to post Share on other sites
Lolsav 0 Posted June 12, 2007 Do you really need it to be scripted? You can get the same effect with the command lookAT Share this post Link to post Share on other sites
fasad 1 Posted June 12, 2007 Trig surely <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">angle = atan deltaX/deltaY or this (better, since no chance of /0 error) <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">angle = deltaX atan2 deltaY where deltaX = difference in x pos of points, deltaY = difference in y pos of points. Share this post Link to post Share on other sites
Cloughy 0 Posted June 12, 2007 I don’t think the LookAt command will work. Its used in a script, that projects the vehicle in the dir its looking. Good for boats and Cars driving into road blocks. Fasad, would the command you provided me with, give me the direction I require? Cheers GC Share this post Link to post Share on other sites
Blanco 0 Posted June 12, 2007 Try this <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _loon1 = _this select 0 _loon2 = _this select 1 _hdg = ((getpos _loon1 Select 0) - (getpos _loon2 Select 0)) ATan2 ((getpos _loon1 Select 1) - (getpos _loon2 Select 1)) ?_hdg < 0: _hdg = _hdg + 360 ?_hdg > 360: _hdg = _hdg - 360 ~.1 hint format ["hdg: %1",_hdg] Share this post Link to post Share on other sites
fasad 1 Posted June 12, 2007 blanco's code will (probably - I just got up! give the heading from _loon2 to _loon1. Use _loon2 - _loon1 for the opposite bearing. Have you tried using doWatch? Share this post Link to post Share on other sites
mr.peanut 1 Posted June 12, 2007 Change: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">?_hdg < 0: _hdg = _hdg + 360 ?_hdg > 360: _hdg = _hdg - 360 to <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">(_hdg + 360) mod 360 Share this post Link to post Share on other sites
Cloughy 0 Posted June 13, 2007 Thanks, I will give it a try at lunch on my laptop, in work at the mo. Cheers GC Share this post Link to post Share on other sites
Cloughy 0 Posted June 14, 2007 Got it working. Cheers GC Share this post Link to post Share on other sites