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][1].

Any idea if this can be done using some shader script?

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.

Hi Stormrage256,
did you find a solution for making a vision cone that got blocked by static objects? (as in the video above)

Yes, I’ve released it as part of the Top Down Stealth Toolkit. It’s using custom meshes with line traces to detect objects in front of the player. The method is quite expensive, especially when you have lot of these present on the screen at the same time. But I’ve found out a few hacks to actually increase the performance like cancelling the line trace calculations when off screen, or when not close to any obstacles.

So i supose that you use one mesh for each degrees then? Oki, would be nice to do it someother way. I’ve been thinking about using som sort of masked Material instance. Maybe will look into it later. Cheers

When I was first researching on this topic, I came across an asset in the Unity Marketplace that seems capable of making dynamic vision arcs much better with a GPU based approach. You can check it out here: GPU Line of Sight

From what I’ve seen so far, it seems to be one of the best implementations out there. Maybe it would help you out in your venture.

Thanks, I’ll check it out!