Advertisement

Finding best direction

Started by June 22, 2001 08:23 PM
2 comments, last by Ratman 23 years, 7 months ago
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
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.

Get off my lawn!

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

Get off my lawn!

wow thanks! I like your book btw

This topic is closed to new replies.

Advertisement