How to visualize and detect line of sight?

If you look in the upper right corner, you will see a line of enemy units on the radar.

I was wondering what is the most efficient or easiest way (small code, fairly accurate, should not be ideal) to find that something is in your field of vision? I may or should not display it (I most likely will not).

I don't know the formula and haven't used any math libraries / namespaces in C #

-edit -

This is mainly a 2d prototype. nothing should be perfect, and he will have a moving camera, units, and it will look only upwards, but not diagonally. There may be a direct line of sight to the wall, but nothing else. Also, other enemies should not trigger an action when they enter it.

So I really need a source (enemy), dst (player) and see that the walls block my vision.

alt text http://image.com.com/gamespot/images/screenshots/gs/action/metalgearsolid/metalgearsolid_790screen001.jpg

-edit- I ended up using rect. This was good enough, and I was able to work on another prototype, then writing raycast code.

+2
source share
1 answer

It really depends on how the geometry of the world is set up, but the usual method is through beam casting . That is, you draw an imaginary line between yourself and the enemy (or whatever interests you), and query the environment to see if there is any geometry intersecting this line.

(, BSP , ..).

+3

Source: https://habr.com/ru/post/1742410/


All Articles