Friday, May 31, 2019

unity - How can I record from a second in-game camera and later export it to a video file?


I'm making a PC Horror game in Unity, and I want to have a camera recording simulation in-game - so you can leave a creepy location anytime, and you will have a tape with what you recorded on camera while exploring.


Technically, I need to attach a second camera (hand-cam) to the character's hand, and let the player look through the viewfinder by pushing a button. But in any position, the hand-cam must record everything that is in its focus at that point - floor, stairs, rubbish, etc, whether it's lowered at hand level or raised to match the player's viewpoint.


When the game ends (player leaves or dies), I'd like to have an option to save recorded tapes to a video file (if this is not possible, then to some save file).



How can I implement such a feature in my game? Are there some special Unity tricks, or add-ons and additional modules? Saving decorations and scenes with active triggers, or just grabbing video from screen?


Below is a quick MSPaint concept of what I mean:


concept



Answer



You need to render your scene twice.


First, you render the scene from the view of the camera to texture.


Then you render the scene from the players point of view, but with the texture applied to the cameras screen.


What changes between the two render passes is the camera transform used, while the camcorder uses the orientation & location of the camera, the players view uses the orientation & location of the players head. If you're using skeletal animation, this would be as easy as attaching the camera model to the player models hand.


Since you already render to texture then, saving a video would be as easy as saving the texture each frame. When the user chooses to save the video, you could convert this sequence of images to a video format.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...