Archived

This topic is now archived and is closed to further replies.

Ratman

Finding best direction

Recommended Posts

In my Iso game I need to have a unit be able to fire at a unit that is say, 6 tiles down and 2 to the left. This doesnt line up nicely with the 8 directions. So I need to approximate a direction to have him face while he fires. What ways have you guys done this? Ive tried a few algorithms but Im not too happy with the results... Thanks, Ratman --------------- Ratfest.org

Share this post


Link to post
Share on other sites
on a diamond map (or for other maps as long as you convert the map coordinates into diamond map coordinates), you can simply take the difference in the coordinates, apply atan2 to find the angle, multiply by eight, divide by 2*pi, add 0.5, make sure the number is in the range 0 to 7 (adding or subtracting eight until it is so), and you''ll be on your way to getting there.

Share this post


Link to post
Share on other sites