New year, new plans! I want to start writing more here, so I’m starting with a dev log. I plan on following a loose weekly release schedule. Should be fun!
Work on the movement/interaction system has taken up most of the week. In the game, I want the player to be able to open compartments, open hatches and slide out equipment from the racks on the walls. The player would open and interact with these items by grabbing handles attached to them.
I started with compartment doors this week. This may sound like a simple problem, and in a normal standing VR experience it would be. The fact that this game takes place in zero gravity greatly complicates things, since the player moves by grabbing handles as well. This means that the position and rotation of the compartment door is dependent on the player’s hand position, and the player’s hand position is dependent on the position and orientation of the compartment door. Instead of just using the player’s hand position to control the movement of the compartment door, I now additionally have to take into account the velocity of the player, the angular velocity of the door, and whether or not the player has their other hand planted to provide leverage.
Currently, I don’t have the math quite right yet. I have logic set up to allow the player to open the hatch if they have leverage, but it currently doesn’t take into account the velocity of the player and the door. I have some ideas of where to go from here though, hopefully I should have them implemented this week. Once I have that working I should have a good framework to start on the hatches and sliding bits, since they are all similar problems.
Camera and the Skybox
One of the first objects i put in the game was a DSLR, so the player could go around taking pictures. It was a good object for testing out the system I built for controlling how the player’s hands grip items, as well as my system for passing input from the Vive controllers to items. More importantly, it’s fun too!
Over the past few weeks I’ve had a nagging problem: the DSLR was not compositing in my skybox. The game uses a two-camera system for doing rendering, one draws the space station, and the other draws the stars and the Earth. This allows me to give a sense of scale to the planet without making it massive, and will also allow me to simulate the station orbiting the planet without actually moving the station. The DSLR was only rendering the station, however.
Compositing cameras in Unity is normally pretty simple. Each camera has a “depth” property that controls the order that it is rendered in. By rendering the skybox first, and then rendering your scene with a camera set to clear the depth buffer only, the cameras will draw on top of each other.
In this case, it wasn’t that simple since I was using a render texture to get rendered frames from the DSLR to display on the camera’s viewfinder. It seems that Unity only writes the color buffer to the render texture from the camera the render texture is attached to, not including colors from previously rendered cameras. This appears to be happening before composition occurs.
Here’s how I fixed it:
- Create a render texture in code (I cached this so I wasn’t making a new one every frame)
- Copy the render texture to the skybox camera
- Call Render() on the skybox camera
- Remove the render texture from the skybox camera and copy it to the DSLR camera
- Call Render() on the DSLR camera
- Remove the render texture from the DSLR camera, and then make a texture from it.
What this means is, render textures respect the clear flags on cameras, and happily support compositing. You can see the results in the video at the start of this post!
This is hugely important for me, because I’m going to be using this technique often. The station will have multiple cameras monitoring the station exterior, and they will all need to support composition.
All told, I’m very excited by my progress this week. The DSLR composition issue has been bothering me for weeks, so it’s feels really nice to have it figured out. I feel really close to cracking the compartment door problem as well. Next week should be an interesting week!