- Home /
How can I make a gameobject partially invisible by distance?
Hello everyone. I am a new on Unity, and I am trying to make a gameobject partially invisible when the portion of it is nearer than a threshold distance and partially visible when the part of it is further than the threshold distance. Could you give me any clues? Thanks everyone.
It's a bit complicated to do as a beginner, not recommended to do it now, maybe comeback to this idea later, but if you really want to. So I bet this is a Unity Shader. Shaders are responsible for rendering objects on the camera view, you have to write your own or maybe look for something completely ready on the internet. (Unity's guide on Writing Shaders)
Answer by jackmw94 · Nov 18, 2020 at 10:43 PM
Might be a bit basic for the effect you're trying to achieve but you could modify your camera's far clipping plane? In the camera's inspector there will be near and far values, set the far value to your threshold and this will only then render up to that distance.
If you have objects in the background that need to be seen then you'll have to setup two cameras, each rendering to the same display but with different culling masks for the layers viewable at different distances.
If this looks/sounds promising then let me know if you need any clarification or help with setting this up :)
His image shows visible objects after the threshold, in which case the near clipping plane would have to be adjusted rather than the far clipping plane.
Ahh yeah, I read that wrong! That might mean that you see the weird insides of meshes.. I see why Crakker’s comment said it would be a shader thing now.
Thank you for your replies. Actually, I have tried giving a near clip threshold for camera. However, the result was not what I expected. It simply make entire gameobject invisible not only making partial part invisible. And also I want to give distance threshold only for the forward direction but the camera's near clip was changed by following my head movement (Rotation). I am still looking for camera API but not sure. Should I study shader?
If camera stuff is making an entire gameobject invisible and is not suitable for you, than of course you should study shaders, can't really help you with that, sorry ;)
Answer by Llama_w_2Ls · Nov 21, 2020 at 07:04 PM
You could also use the LOD system by Unity and set the second layer of detail to a mesh without any triangles and vertices so it is practically invisible. Then, when you get closer, the visible mesh appears. @dyhan113 if you wanted.
Your answer
Follow this Question
Related Questions
cameras rendering problem 4 Answers
How do I check if a GameObject is visible by a camera? 1 Answer
Rendering a Pygame surface in Unity 0 Answers
Improve render quality? 0 Answers
Create texture from current camera view 3 Answers