How to implement a visible cone of vision?
Hey, I want to implement a cone of vision for my AI guards that the player can see in game.I don't know how I'd go about implementing something like this whether it be in code or Blueprint. I was thinking something similar to how Volume does it here.
I did something similar, both with a visual cone and without. They are two separate objects.
First, the visual cone is pretty easy. Just create a static mesh and give it a translucent material, attach it as a static mesh component to a socket off of the head. Then you can toggle the visibility through blueprint.
Second is a bit more complex. I did it in blueprint for when an AI is in my flashlight's range. It could be carried over to an AI's sight though (I'm actually about to do that. I'm making sheep AI!). So if you can get the location of the target (the player) and the location where the sight is being emitted (AI eye Socket). Subtract one from the other and normalize it to get the direction of the sight location to the player.
Separately, get the world rotation from the sight location. Get the forward vector of that.
Then get the Dot Product of the forward vector and the direction to player. Compare that to a # to get the angle of your cone. I did mine at .75 If the target (player) is in the cone, then it returns true. If they're out, then it returns false. You'll probably need to put a distance cap on it too to match up with your visual.
Here's a pic of how I did mine to match the description above.
answered Oct 02 '15 at 09:40 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here