Hi everyone, I have a maths problem that I'm struggling with, and I was hoping someone could help.
I'm doing a top-down game, and I would like an arrow to point to the next objective if that objective is off-screen. I have set this up no problem - when the objective item is not on screen then I am:
* setting the arrow's poition to the the player's poition,
* setting the arrow's angle towards the objective,
* moving the arrow 200 pixels forward at its current angle.
This works OK, but rather than move the arrow 200 pixels, ideally I would like to figure out the distance between the arrow and the edge of the screen, and move it forward by that number of pixels. That way the arrow would stick to the edge of the screen, if you see what I mean.
So I know the X & Y of the viewport, and the angle the arrow is pointing, but can't get the next step. I'm sure there's some trigonometry that could help me here, but I'm struggling. Any ideas? Thanks