Mesh fading

I’m just about done with the rpg course, but one thing that bugs me is that I suck at level design and almost always end up putting a wall or house or something that will get between the camera and the player to the point where I can’t see anything. In games like diablo it looks like the mesh of the obstructing object fades out when needed and back in after. I know the concept is to spherecast from the camera, detect the obtrusive object, and then fade out the material but i can’t seem to get it to work. Anyone have any ideas?

I would put the objects you’re trying to “fade” on their own layer… then spherecast the Camera ray to the player…

You’ll need to put a script on the object that you can tell to do the actual fading, and more importantly the unfading when it’s no longer detected…

public void FadeMe()
{
     faded=true;
     /// Do fading stuff
}

void Update()
{
    if(faded) 
    {
        wasFaded=true;
        faded=false;
        return;
     }
     if(wasFaded) 
     {
         wasFaded=false;
         ///Code to unfade
      }
}

You’ll need all the variables I mentioned set up in global, of course.

In terms of fading the materials, they’ll need to have shaders set up for transparency… Unfortunately, the Standard shaders while set up for transparency, don’t easily expose the Alpha to the code… Also, the shader needs to be capable of instancing. All of this is outside the scope of the course.

In the meantime, however, to prove the concept in the detection/fading you can do this in your fade/unfade logic:

void PerformFade()
{
    GetComponent<MeshRenderer>().enabled=false;
}

void UnFade()
{
    GetComponnent<MeshRenderer>().enabled=true;
}

That assumes that the mesh is in the same component as the script/collider.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms