I have read your discussions here and you are getting near to a solution. @EDarkness solution is a good way to go.
First let us keep it simple and avoid any advanced shaders, post process image effects or render textures as we are on Unity Free.
Lay out the steps we need for this to work:
1: Cast a ray from the camera to the player at all times.
2: Add all objects the ray hit which is not the player into a list.
3: Disable the renderer for all those objects.
4: Remove Objects from the list that the ray no longer hits.
5: Enable the renderer on all of those objects again.
We want to add all objects we find because there could be multiple objects in the way, but we could also of course keep it simple and say that we only want to hide Walls and Pillars and not other small objects. Still it is wise to be able to hide all Walls and Pillars we find.
So here is my example code to accomplish this:
using UnityEngine;
using System.Collections.Generic;
public class HideWalls : MonoBehaviour
{
//The player to shoot the ray at
public Transform player;
//The camera to shoot the ray from
public Transform camera;
//List of all objects that we have hidden.
public List<Transform> hiddenObjects;
//Layers to hide
public LayerMask layerMask;
private void Start()
{
//Initialize the list
hiddenObjects = new List<Transform>();
}
void Update()
{
//Find the direction from the camera to the player
Vector3 direction = player.position - camera.position;
//The magnitude of the direction is the distance of the ray
float distance = direction.magnitude;
//Raycast and store all hit objects in an array. Also include the layermaks so we only hit the layers we have specified
RaycastHit[] hits = Physics.RaycastAll(camera.position, direction, distance, layerMask);
//Go through the objects
for (int i = 0; i < hits.Length; i++)
{
Transform currentHit = hits*.transform;*
//Only do something if the object is not already in the list
if (!hiddenObjects.Contains(currentHit))
{
//Add to list and disable renderer
hiddenObjects.Add(currentHit);
currentHit.renderer.enabled = false;
}
}
//clean the list of objects that are in the list but not currently hit.
for (int i = 0; i < hiddenObjects.Count; i++)
{
bool isHit = false;
//Check every object in the list against every hit
for (int j = 0; j < hits.Length; j++)
{
if (hits[j].transform == hiddenObjects*)*
{
isHit = true;
break;
}
}
//If it is not among the hits
if (!isHit)
{
//Enable renderer, remove from list, and decrement the counter because the list is one smaller now
Transform wasHidden = hiddenObjects*;*
wasHidden.renderer.enabled = true;
hiddenObjects.RemoveAt(i);
i–;
}
}
}
}
This assumes that all objects that has the layer mask has the renderer on the same object as the collider. If not then you should use GetComponentInChildren() instead.
I have not tested this code very thoroughly, but It should work. Or you can at least base your system on it.
After getting this to work we could expand on it and get the objects to fade in and out using the color of the shader instead of just simply turning them on and off.
With a top-down view (birdsEye?,) a player will rarely be blocked, right? Only pressed against the far side of a wall tilted by perspective?
– Owen-ReynoldsWell, its not exactly above the player since there is a small difference on the x position and the x rotation in order to give a better view of the character therefore the character can sometime be hidden by walls and thats why diablo used the system of making walls disappear (or at least the part of that hides the character) in order to have a better visual of the player..
– abdosaher