- Home /
Raycast from a 3rdp controller
So the issue I'm having is that I'm trying to check if a "enemy" or obstacle is within my visual radius. If it is then set col.gameObject.renderer.enabled = true; As it is now im only checking if they are within a certain distance of the player, but I want to narrow it down to the field of view.
My characters field of view is cone shaped (he's holding a flashlight with a spotlight attached to it) and as long as the gameobjects aren't inside the light they should be hidden (renderers turned off).
What is the best way to solve this, have had a lot of problems with raycasting and such, so I'm now turning to the forum for help
Regards Robert
hm spot light
try with search light and if it is in radius of search light than ok
you can set distance of search light
it has cone shape you can change the ° of it well I'd give code but I'm not there yet just giving some directions on how would I try solving
even more you can turn it's illu$$anonymous$$ation to 0 and it does not light in front of you
Answer by Robert Carlsson · Mar 17, 2014 at 10:39 PM
Sorry that I haven't replied. The way I solved it was by checking if an enemy was within my screen(or visual range). Then I calculated if the enemy was within an angle of -22.5 to + 22.5 infront of me. If it was I rendered it, otherwise I didn't.
Will mark it as solved.
Your answer
![](https://koobas.hobune.stream/wayback/20220613091414im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Fog Of War with line of sight - Tons of raycast or better solution? 0 Answers
Enemy Ai Field of View 0 Answers
How to make Syndicate-style civilian AI without horrible slowdown? 2 Answers
How can I get the rotation of Handles.DrawLine to match up with an Objects forward? 0 Answers
Field of view, using raycasting 5 Answers