#### Archived

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

# 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.

## 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 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 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 on other sites
wow thanks! I like your book btw

1. 1
2. 2
Rutin
20
3. 3
4. 4
frob
15
5. 5

• 10
• 9
• 14
• 9
• 33
• ### Forum Statistics

• Total Topics
632592
• Total Posts
3007295

×

## Important Information

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!