- Home /
Detecting objects between camera and mesh
I'm trying to come up with a way to visualise a characters field of view in a 3D isometric world.
The current setup has a mesh representing the field of view attached to the character which is generated every frame (as per Sebastian Lague), with a shader writing to the stencil buffer.
There is a then a semi transparent plane between the camera and the world, with a shader that uses the stencil buffer to cull the pixels matching the mesh.
This all works, but now I'm trying to figure out a way to fade out obstacles which sit between the field of view mesh and the camera, so that what the character "sees" can be seen by the player.
Using the stencil buffer method above doesn't give a great visual effect - what I'd prefer would be some way of detecting if any part of an object is sitting between any part of the field of view mesh and the camera, so I could then fade out the whole object.
Effectively this sounds like creating a mesh collider from the field of view mesh, and casting it towards the camera and fading out any colliders that it hits.
Rigidbody.SweepTestAll seemed like it might be the answer, but only works with convex meshes - the field of view mesh is not convex as it deforms around obstacles in the world.
Any advice on whether I'm barking up the right tree, or if there's a more appropriate tree I could have a go at, would be much appreciated.
Your answer
Follow this Question
Related Questions
Level Creation, Prefabs and Colliders 2 Answers
make object to appear from bottom up 2 Answers
Transparent/Disappearing Walls When Entering Room 0 Answers
mask one gameObject mesh by another mesh vertex transparency 1 Answer
My collider is offset from where it appears in the scene editor when I'm in gameplay mode 1 Answer