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!
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.
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.