I am making a simulation and currently adding obstacles to it.Now the purpose of the obstacles is so that other agents could hide behind them where others then cannot see them.However I am trying to figure out what would be the best approach to check if an agent in view is behind an obstacle and therefore could not be seen.Here is an example:
The agent in black should not see the agent in red but however should be able to see the agent in yellow.(The green lines indicate the field of view of the agent in black)
At the moment my field of view only calculates the angle that agents are at and checks if the angle is within the field of view. I was looking at some things solutions that game developers use and was reading on ray-casting however it seems like its very computationally heavy and is not a good solution for me as I will have hundreds of agents casting rays.
Another thing I was thinking is checking the angles that the obstacle occupies (e.g from 90 to 120 degrees) of the view and if the agent is in the same angle span than that means he is blocked by the obstacle.(If that makes sense).
I posting here in order to ask if anybody could guide me to a simple yet efficient solution for this as I am very new to this sort of game-development related things.
Thanks in advance!
If it is 2d, then create two lines (shown in blue) and test for distance between line and agent. The distance from blue line to agent must be at least an agent radius or the agent is visible. Also give each blue line a perpendicular "Normal" vector that you can Dot against to determine which side of the line it's on. If it is 3d you do the same but use planes instead of lines and you will need 4 or mor planes instead of 2. In essence, this is how frustum culling is done.