Hey all! I made this a couple weekends back as part of a pet project I’m working on, figured I’d share with the class. I wanted to emulate the wall hiding feature in Diablo in my game, where the geometry that blocks you from the camera fades away as you move behind it, and fades back in as you move in front of it. Note: There are many ways to accomplish this task, but this is how I went about it (Forgive the non-uniform screen grabs, its late)
To approach this problem, I broke it down into the two parts that would be interacting - The Player and The Wall.
I knew I needed to know when my player went behind or came out from behind the wall. These two Events needed to trigger two Actions - Hide and Show.
The Player causes the events, the wall receives the calls to action.
The Wall - Hideable_Actor
Since I wanted to fade in and out over time, I knew I needed to handle the fade using the Tick function’s delta, and a Material instance of a material with a scalar parameter into it’s Opacity channel. See 3 pictures down that I set this up as a dynamic material instance as well, and cached it to a class variable on the EventBeginPlay.
Fading over time meant I’d have to do some internal state control on the Hideable_Actor, and I handled this with two booleans - **ShouldHide **and ShouldShow. Using these two variables, The blueprint could decide whether or not it should UpdateVisibility, another function I added to control the fade at each frame via Tick. If either of these was true, the fade would happen in the appropriate manner. I even added a fadespeed so I could make the fade in/out faster by multiplying it by the Tick’s delta.
Inside the UpdateVisibility function, I set the opacity parameter on my dynamic instance by a little more, up or down based on which boolean was true. I used some logic to clamp and reset the ShouldHide and ShouldShow booleans in order to stop the function from being fired once the desired opacity was achieved.
I built the wall to have two public functions to handle these actions - **Hide **and Show - that could be called by an outside force. These basically just toggle the booleans for ShouldHide and ShouldShow.
And that’s it for the Wall.
The Player
I build this originally from a modified version of the topdown content example. Basically, I re-positioned the camera to something a bit more what I was looking for, and added a long, scaled Box, used as a trigger in between the camera and the player mesh. This box will be what we use to test if the player is going behind the wall.
With the box selected, I added our events, choosing **OnComponentDidBeginOverlap **and OnComponentDidEndOverlap. In these events, I cast the OtherActor from the Event to our Hideable_Actor, and do the appropriate function based on going behind or coming back out. When the box overlaps with the Hideable_Actor, we want to hide. When it’s no longer overlapping, we want to show.
And here is the result!
Before
After
And again in horrible, phone recorded glory from my vine
Thanks for playing! :rolleyes: