how can I make a player hidden by terrain always visible?

387 Views Asked by At

I am making a 3D isometric game, in my game, there is a lot of holes and the player can go into them, but the problem is when he goes into one of them he becomes invisible, I can,t move the camera it will change the concept I tried using shader like the one in this video but it makes the entire terrain transparent and glitchy (I am using unity terrain) so I am stuck and I need Idea how to make the layer visible inside the hole

2

There are 2 best solutions below

3
Juris On

What you're asking can be achieved in multiple ways, depending on your render pipeline and requirements.

If you're working with the Universal Render Pipeline (URP), you could create a Forward Renderer asset and create a custom render pass whenever your player is occluded by terrain.

You could assign a new Layer to the player, such as "Player", then select or deselect said mask from the Filters > Layer Mask properties of the Forward Render Data. Then assign the same or a custom material for when the player is occluded by terrain.

Forward Renderer Data

Alternatively, you could create either a cutout or a dither shader using Shader Graph, on which there are many tutorials

3
Mylonas K. On

Camera GameObjects give you the option to select what layer you want them to "see" (render) using the culling mask. Think of layers as grouping GameObjects and giving that group a name.

You can have multiple cameras at the same time each one with a different name and different layer to render, or even change the viewing layer of a single camera depending on changes happening in the game.

Assign a layer tag in each of the terrain elements in your scene and have the camera render them accordingly and "cull" the rest.

Very helpful documentation on layers and camera culling mask.