I notice in a lot of horror games, for example ‘Layers of Fear’ they’re able to change the room around the player when they aren’t looking. The room you just came from will be completely different when you go back, the door will disappear, or you’ll turn around and everything will be completely rearranged. I cannot figure out how to accomplish this inside Unity; I’ve thought of destroying and instantiating objects, but that seems like a ton of code and lag, and teleporting the player to another room, but I don’t see how you’d teleport them to the corresponding coordinates to make it work flawlessly. Can anyone with experience give me tips?
You’ve got it mostly right, but you have to find a different way to do the things that are more expensive on the CPU.
Instead of creating entire objects and rooms behind the player when they aren’t looking, have those objects already loaded, but deactivated, then reactivate them when they should “appear”. Likewise, deactivate GameObjects instead of deleting them until you’re done with the whole scene.
For the “teleport the player to an almost identical room” approach, first make just one room and child everything to a “Room” GameObject. Duplicate the room and make any changes you wish (removing doors, etc.). Now make the player a child of the first room. When you want the player to teleport to the same place in the duplicate room: copy the player’s local position, set the player’s parent to the new room, then set the players local position back to what it was in the previous room. You may also want to do the same for local rotation and local scale.
There’s an infinite number of tricks you can use to make the scene change around the player. The trick is to do it the easiest way you know how, find out what’s slow or not working, and try to fix those things specifically. Best of luck!
Thank you very much!