Jump to content
  • Advertisement

Archived

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

Ratman

Finding best direction

This topic is 6298 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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!