Why does my FoV toggle on and off based on camera position in the scene?
I followed Code Monkeys Youtube-tutorial "Field of View Effect in Unity (Line of Sight, View Cone)".
This is a top down shooter. I´m rendering a scripted mesh cone in a FoV gameobject that is positioned at player position and reveals surroundings towards mouse position. Revelation is based on layermasks. RayCast2D detects obstacles that you can not see through.
Everything works fine. Obstacles are blocking and enemies are hidden when out of FoV. The problem is that when moving away from center position of the scene the FoV cone turn of at a certain point. If you walk back again the cone turns on. The problem only occurs if the camera is moving as well. If the camera is static everything works fine. If I zoom out the camera I can walk further than with a more zoomed in camera. Everything seemingly looks fine in the scene view, even though the cone is not rendering in game view. I dont know how to use frame debugging, but I noticed a difference in rendering between when the cone is rendering and not. Under Mask - RenderLoopNewBatcher.Draw I see two draw calls when FoV is working and non when its not. Under preview there is more Vertices and Indices then when it´s not working (V:617 I:2604 vs V:515 I:2304).
Im really confused and don´t really know where to look for the bug. If anyone could point me in the right direction it would be great.
Regards - Erik
Your answer
![](https://koobas.hobune.stream/wayback/20220612224459im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Obj model invisible in game 0 Answers
mesh sorting problem? heelp! 1 Answer
voxel stack rendering from mandelbulb? 0 Answers
Please help with mesh render order 0 Answers