Jump to content
Sign in to follow this  
tpw

Direction between two objects - preferably without trig!

Recommended Posts

I'm working on an enemy spawn script that announces the direction and distance to the enemy location.

Distance - no problem!

Direction between player and enemy position, hmmm. I guess it could be done using trigonometry from map coordinates. But I'm sure I read somewhere that there is a newish armascript command for determining the direction of one object relative to another. Can anyone help with this?

Share this post


Link to post
Share on other sites

Fire up the function library. I believe there is some function that does exactly what you want. I cant search it for you atm, but you should be able to find it in the lib.

Share this post


Link to post
Share on other sites
Fire up the function library. I believe there is some function that does exactly what you want. I cant search it for you atm, but you should be able to find it in the lib.

Nah, it's for ArmA2 AFAIK.

Share this post


Link to post
Share on other sites

Ok, for A1, you still need some trig, but it is not too hard. I'm digging this out of an OLD script, so it may require some testing.

_orig = origin position

_dest = destination position

The result of this formula is a direction (0-360) from the origin to the destination.

_vector = ((((_dest select 0) - (_orig select 0)) atan2 ((_dest select 1) - (_orig select 1))) + 360) % 360;

Now, I used to be able to explain the trig... but... not anymore. :)

G'luck.

Share this post


Link to post
Share on other sites

Thanks kind sir, exactly what I needed. I actually don't mind a bit of trig as long as I don't have to think too hard about it!

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  

×