Search code examples
unity-game-enginereflectionartificial-intelligencepath-findingraycasting

A way to find the angle at which to emit a ray so that it hits the target. With the source and target known


I wanted to make an AI that makes the decision to shoot a reflecting laser towards the target accurately from it's position, reflecting from a stable, non moving smooth surface like a mirror.

One option is to rotate the ray until it finds the position to hit the mirror so that the laser hits the target after reflection. But I would like to consider more options apart from the apparent brute force method.


Solution

  • enter image description here

    1. Find the Perpendicular intersection(C) from Player(P) to the reflection plane.
    2. Then find the Transpose point (T) of P. Meaning, C will be the center point of T and P.
    3. Raycast from AI(A) to T. Let the hit point be X on the reflection plane.
      or You can just ignore 3rd point and shoot towards Vector (T-A)

    Then X will be the point where the AI should hit. You can try out this link for finding the perpendicular intersection:
    http://www.ambrsoft.com/TrigoCalc/Plan3D/PlaneLineIntersection_.htm