How to make a black cube of fog to hide what's behind it?

Hi, I was wondering how to make some kind of cube of fog that essentially prevents light from going through, making it easy to hide parts of the level from the player. I know theres tutorials out there of making fog but I wanted to know what the correct way is when it comes to making it for video games.

You can see what I mean at 6:04 in this video: https://youtu.be/em9EP_pLJ6U?si=V2KrFKY8LZ79ibrR

And in this one at 4:22 https://youtu.be/DoGpATmjcjo?si=djR1L2OU_8RO4mrK

Any help is appreciated