How to make camera render only the inside of a secret room?

Hi guys , I´m working on a little 2d metroidvania style game with a couple of friends . Recently we talked about how cool it would be to have secret rooms in the game , and by secret rooms I mean little areas that are behind what looks like a normal wall but you can only see what is inside them when you enter the room . Something like this at 7:23

Hidding the room behind a fake wall would be pretty easy , the question here is : How do I make the camera only show what is inside the “secret room” when you are actually inside the secret room , making everything outside the secret room invisible (in the video´s case , completely black) ? Is this a problem that can be solved with camera functions/tricks or is there some way to achieve this via sprites/textures etc?
I really hope some of you can help me.

1 Like

The easiest way I can imagine doing this, is to have a (or more) wall parts that is above the secret room to disappear when entering it. Imagine it as a lid that opens when you enter it.

This can be used in the same way I created the Roof script in my 2D top-down game I am working on. Check on the RoofScript.cs in my post :slight_smile:

Still a work in progress, but it should get the job done!

Any ideas on how to make everything outside of the room “disappear” while you are inside it?

Here’s one way you could do it (I think this is the easiest way, only takes a few lines of code, and does everything you want it to do)

You could put everything in the secret room under the same layer (lets call it “SecretRoom” for an example),

On the Main Camera/Players Camera, Set the Culling Mask to Everything BUT SecretRoom,

Put a trigger over the secret room,

Use OnTriggerStay to Set the Culling Mask on the Main Camera to Nothing BUT SecretRoom,

Use OnTriggerExit to set the Culling Mask to Everything BUT SecretRoom,

You can change the Backround color on the Main Camera to change the look of the part that’s hidden. (You could do many things with that, for example make it fade into the color black when you enter the secret room)

-=-=-=-=-=-
OR
-=-=-=-=-=-
Instead of placing a Trigger over the entire Secret Room, You could use 2 Triggers Next to each other near at entrance of the Secret Room,

Then use OnTriggerExit on the one closest to the exit to Set the Culling Mask on the camera to Nothing BUT SecretRoom,

And use OnTriggerEnter on the one next to the “Exit” one to set the Culling Mask to Everything BUT SecretRoom,

That Second way MAY be a little confusing :eyes: , But it may be easier then the first way…

-=-=-=-=-=-
The way I typed it may make it seem a little confusing but it’s real easy to implement.

BTW I did this in colors cuz i was bored and I never have done it before.,.,.

If yah can’t read it clearly I can change it back to black xD

2 Likes

Thank You so much for your help , both of you . I really appreciate it