• Advertisement

Archived

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

Finding best direction

This topic is 6087 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
IsoLook.zip

I wrote this just this morning, to show you what I mean. It has full source and executable. It''s a rather simple demo using GDI.

Share this post


Link to post
Share on other sites

  • Advertisement