0
votes

Note : I am coding in Unity, using C# script. I cannot use trigger hit detection using Raycasting because there are a lot of trigger colliders in between the target and source which detect touches and the sort. So the ray hits the other triggers before even reaching it's target, which is not desirable.

What I want to accomplish basically is return a boolean value if a vector line crosses or intersects a particular set of vector coordinates or an area. For example: Detecting a laser entering into a fog in between it's path when shooting at it's target. The fog is a trigger collider based game object.

Edit: Another example would be to check if a line crosses a 2D box area in a 2D graph. Keep in mind, I cannot use collision detection or Raycast hit here.

There is no need for code, just explain the concept of how it could be accomplished. Though a code snippet is also welcome. Thankyou!

2

2 Answers

1
votes

[...] So the ray hits the other triggers before even reaching it's target, which is not desirable.

What about putting that on Layers? You can specify LayerMasks for Raycasts.

0
votes

You could consider the edges of the 2D box as lines i.e 4 lines and check for intersection of a line with these 4 edges using line to line intersection technique. If the line however is small enough to fit inside the box, and you want to treat it as a valid intersection, then check if the two points of the line is inside the bounds of the box.