- Home /
How can I make a part of a mesh to be invisible - ie: see through parts of walls...
I have a 3rd person camera that has it's .forward always pointing towards a specific object.
Occasionally this object finds itself behind other objects/meshes (like walls for instance).
I have a script that checks if this main object is visible by casting a ray from the cam's forward/center to this object's position.
I would like to be able to make a "hole" in the any mesh hit by the ray that is not the main target object described above; I would like this hole to originate from the rayHit.point's position.
I'm thinking the hole can only be an illusion, perhaps a superimposed alpha mask texture that will hide a circular subsection of the wall's alpha.... (like a square image, all transparent, with a black circle in its center).
How can I do this in script? Apply an "layer mask" to a material...?
Or perhaps another way of accomplishing what I am describing...?
Thanks!
The approach you're describing requires you to render the scene with multiple cameras and use render textures to mask at least one camera's final output with a screen-space alpha mask centered on your VIP. This requires Unity Pro, and, frankly, more know-how than I currently possess.
It's also possible that you could use a shader to accomplish this - a shader which fades the alpha of any pixel in a certain screen-space region (centered on your VIP). For this to work as intended, any object you ever want to "see through" in this fashion must use a shader with this feature. Yet another task I lack the knowledge to recommend.
The render-texture method is definitely preferable, but the shader method shouldn't require Unity Pro.
I'm sure I've seen a blog post or something about doing this. Try hunting for examples where this has been done for better info.
^Agreed. Search for "X-Ray Shader" or something like that.
X-Ray / CutOut Shader with mouse
Edit: Also:
Will have a go at those two links you posted, looks promising! thanks.
Answer by wesleywh · Mar 02, 2015 at 05:01 PM
I know this isn't quite the answer your looking for but you could add a texture that is see through to the object when it's hit with that ray. Just make some texture with 50% opacity and import that texture to unity and use that texture when it is hit with the ray.
That's actually how I currently have it setup. A script casts a ray every frame from cam center, along cam forward, and sends a message to every non-main object encountered to "disappear", which triggers a change of shader (to translucent + shadow) and gradually changes alpha over time. This configuration requires a very specific hierarchy setup and drastically lengthens the level-making process... But ya, great idea :) thanks.
Answer by westingtyler · Mar 28, 2020 at 06:07 AM
I had similar troubles with my third person camera clipping through walls and hiding my hero. making the walls invisible or transparent or having holes is one way, but for my needs I solved the problem by switching my camera system to use Unity's Cinemachine free look camera (as of 2020 they have in beta a Third Person Follow camera, which I have not yet checked out) and I blend this with my Cinemachine virtual camera for first-person mode.
But the solution is adding a Cinemachine Collider script, which is built into cinemachine, onto my free look camera. Setting it up to ignore the player tag but collide against other things, and pull the camera forward, means this automatically avoids walls. Tweak to your liking.
It's great that problems like these are so instantly solved by the new additions to the Unity engine. my previous setup was obnoxious by comparison to Cinemachine.
Your answer
Follow this Question
Related Questions
Dymanic Mesh Hiding 2 Answers
Geometry shader output to mesh in Unity 4 0 Answers
Shader - Hide self overlapping mesh 1 Answer