Jump to content
Sign in to follow this  
Cloughy

Calculating the Heading between 2 points

Recommended Posts

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

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

Trig surely smile_o.gif

<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

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

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

blanco's code will (probably - I just got up!wink_o.gif 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

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

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×