0

In my 2D game I would like to have indicators (arrows) pointing to enemy ships which are offscreen.

So far I have defined:

  1. If a ship is offscreen (not in the camera rectangle)
  2. The rotation the arrow should be pointing in (towards enemy ship)

That is all fine. My problem is that I want the arrows to be placed around the edge of my screen - the closest point to an enemy ship without going offscreen.

I would be grateful if the community could point out how this can be done. I'll be happy to post code if required, but to be honest it's just rotation and distance calculations so far. Links to articles would also be great.

Many thanks for your assistance.

  • 3
    Write an algorithm that finds the point of intersection of two line segments. Draw four line segments A,B,C, and D around the edge of your screen. Draw a line segment E from the center of the screen to the enemy ship. Find the point where E intersects one of the line segments A,B,C,D. Draw your arrow there. – Kevin Jul 17 '14 at 13:22
  • Thank you for your comment - I would mark it as the answer if I could! I followed your guidelines and with help from http://stackoverflow.com/questions/3746274/line-intersection-with-aabb-rectangle I was able to achieve what I wanted. Many thanks. – user3256944 salutes Monica Jul 17 '14 at 20:17

0 Answers0