2
$\begingroup$

I'm pretty new to the Mathematics section of StackExchange and need some guidance on some math for a 2d topdown game I am making. In my game there is an Archer boss, who can shoot reflective arrows, which reflect on the walls similar to light i.e. the angle of incidence is the angle of reflection. In order to make the boss smart I want to add a system which shoots an arrow to the wall which reflects to the player. All I need is to find the angle to shoot at so that it reflects to the player (i.e. angle A in the figure). The actual angle I need refers to angle relative to a line drawn from the player towards the top of the stage, the angles increase clockwise (so 0 deg is top, 90 deg is right, 270 is left etc). This is not needed as I can adjust.

What is given for the function is the boss' and player's coordinates and their height towards the nearest wall (Remember that this is a 2d topdown game therefore height towards wall is the shortest distance towards the wall). Using these parameters how to find angle A in the figure?

Here is the image

$\endgroup$
3
$\begingroup$

Just reflect $B$ in the mirror to get a point $B'$ lying in the shaded area of the diagram. Now draw a straight line from $A$ to $B'$. Where this line crosses the plane of the mirror is your point $C$.

$\endgroup$
  • 1
    $\begingroup$ I made a diagram. Also, they are walls, not mirrors. $\endgroup$ – Arthur Jun 11 at 13:18
  • $\begingroup$ This was also going to be my answer. The question has some rather strange requirements--we know the distances $AD$ and $BE$ but do not have access to the location or angle of the wall?--which could make finding $B'$ non-trivial (and even not uniquely determined!). In practice I suspect the question as stated is too specific, and the location of $E$ (and therefore also $B'$) would easily be found using information available to the programmer. $\endgroup$ – David K Jun 11 at 13:28
  • $\begingroup$ Thank You guys so much. This does work, however could u tell me the logic behind how it works. $\endgroup$ – Chris Mathew Jun 11 at 13:36
  • $\begingroup$ @ChrisMathew If you look at my diagram, and make note of all the angles that appear there, you will see that this is exactly what comes out of the "angle of incidence is equal to the angle of reflection" requirement. $\endgroup$ – Arthur Jun 11 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.