| Field of View Tutorial |
| Written by Jeff Brown |
Field of View for Enemies
For the image above, Right Click>Save As and save it to “HighResolutionContent>Overlays” folder (or wherever you see fit, just remember the location for the LoadContent call) Remember to load it into the project solution by navigating to “HighResolutionContent>Overlays” and right click on the Overlays folder and Add>ExistingItem>spotlight2.png.
Add these underneath after public Rectangle BoundingRectangle{...}
Next add the following line in LoadContent method at the bottom:
Now in the Update method add the following at the top:
In the Draw method add the following to the bottom:
Now I’m sure you’ve noticed a few flaws, like Hey, he can see me through walls! or Hey, his field of view is a rectangle… At this point you might want to add clipping (so obstacles block the enemy’s field of view) or change the field of view to something more realistic. The solution to these problems will involve using some math skills you were saving for something like this! I found this to be the quickest solution to test a field of view for enemies. Eventually I’ll make it more complex but this works fine for the near future. |



