Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Diablo-style walls that become visible/hidden depending on the character's location

Discussion in 'Scripting' started by diablo, Feb 1, 2011.

  1. diablo

    diablo

    Joined:
    Jan 3, 2011
    Posts:
    736
    Hello everyone,

    I'm wondering if anyone has any pointers on how to create diablo-style walls that I can toggle transparency so that if a wall comes between the camera and the character the top half of the wall becomes transparent/hidden and if the character is in between the wall and the camera then the top half of the wall becomes fully opaque/visible.

    Any thoughts? Many thanks in advance for any pointers.

    El Diablo
     
  2. Chris-Sinclair

    Chris-Sinclair

    Joined:
    Jun 14, 2010
    Posts:
    1,326
    Best I can figure is to do a Physics.Raycast between the camera and the player. If the ray hits the wall instead of the player, you can then alter the wall's materials (or swap its visibility with a transparent one) accordingly. I'm sure someone will be able to provide more in-depth thoughts, and I'm 99.9% sure something like this has been discussed/implemented before somewhere.
     
  3. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    You could do a linecast between the camera and the player. The result would be the first object that is in the way. Then apply some script to make the material's for the object transparent.

    Code (csharp):
    1.  
    2. var target : Transform;
    3. private var lastObject : Transform;
    4. function Update () {
    5. try{
    6. lastObject.renderer.material.color.a = 1;
    7. }catch(e){}
    8. var hit : RaycastHit;
    9. if (!Physics.Linecast (transform.position, target.position, hit)) {
    10. lastObject=hit.transform;
    11. lastObject.renderer.material.color.a = 0.2;
    12. }
    13. }
    14.  
     
  4. diablo

    diablo

    Joined:
    Jan 3, 2011
    Posts:
    736
    Oh that's interesting... I didn't think of doing a raycast/linecast! Although now I'm wondering how I'm going to make it so that only half the wall is hidden. I guess each wall would have to be made up of two wall sections, each with its own shader, which means I have to split each wall texture as well. Aaaaargh! Nothing is ever as simple as one would like, lol!

    El Diablo
     
  5. diablo

    diablo

    Joined:
    Jan 3, 2011
    Posts:
    736
    Oh wait a second... wouldn't a custom shader do the trick of partially hiding a wall?
     
  6. grim2594

    grim2594

    Joined:
    Nov 5, 2010
    Posts:
    104
    I don't remember much about Diablo 2, but Diablo 3 uses multiple models to give that effect. A raycast can be drawn between the camera and the character. If the camera doesn't have a direct line of sight, it will tell the object in between (if it's a correct type of object) that it needs to fade out. Since the object is multiple meshes/objects it will fade out the part that's blocking the players view.

    Hopefully you already figured this out, since it is such an old post. lol ;)
     
  7. diablo

    diablo

    Joined:
    Jan 3, 2011
    Posts:
    736
    Yeah, Diablo III uses multiple models, but I was looking for an automated system. Theoretically it's possible through the use of a custom shader and a plane which will serve as the cutoff point, but I posted this way back when to see if anybody had any alternative ideas.
     
  8. soulburner

    soulburner

    Joined:
    Mar 25, 2012
    Posts:
    169
    Try searching forum for "visibilty bubble" or something like that. I've seen such a topic before.
     
  9. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,921
  10. CatsPawGames

    CatsPawGames

    Joined:
    Jun 4, 2014
    Posts:
    443
    For those still looking for something along those lines, check See-Through System. It's shader-independent, so no custom shaders or materials required.