Week 6: VR Implementation


 Beat Saber Implementation

This week, we started by creating the floor and a room using cubes. To get the color of the room in black from the inside and outside, we set the material settings to this:


We also added some lines to the scene to make the room look pretty:


Now we create the boxes that the player will hit, and we tried to make them look like the ones in beat saber:




Both boxes are prefabs so we can spawn them in the game.

Now we need the boxes to move forward, so we create a script for the boxes and under the update method, we add a line of code that will do so. Here we are using a velocity of 2 meters by second, by multiplying the position by time.deltatime by 2:


So we add the Spawner, we do so by adding an empty GameObject and add a new script to it. The Spawner script will have the logic to spawn the boxes.



The script will have two arrays, one with the boxes prefabs, BLUE and RED, and one with the place holders of where the boxes will be spawned from. It also has the beat, which is the duration of every when should a box be spawned, and the timer will count the time remaining between two beats and between the spawn of the cube.

In the Update method, we check if it’s time to spawn a new box, if it is, we randomly select the spawning box so the box would be either blue or either red, and also randomly select which place will the box be spawned at. We also add a rotation to our cube using a rotate function and the rotation will be random so the cube will be either right, left, up, down. And we end the update method with updating the timer and adding the deltatime.

Now we create empty GameObject in the scene and these will be the places where the boxes will be spawned at. They will be under the spawner GameObject.


Now we add two new layers, one for blue and one for red, we do that so we can distinguish the red boxes from the blues ones, once we hit them with the saber. So the blue box will be in the blue layer and the red one will be in the red layer. 

Now, it’s time to create the sabers and their logic. So the player will have two sabers, one in blue and one in red, and the players should use the sabers to hit the boxes according to the color. So red hits red and blue hits blue.

So we create the two sabers as cubes, and we add this script to them:


Now that the scene is almost ready, we add the VR setup from last week into this project. We add the OVRCameraRig to the scene, which has the cameras and the controllers anchors.

We move the left blue saber to under LeftHandAnchor, and the red one to under RightHandAnchor.

Next week it will be the time to see if it’s really working.

Comments

Popular posts from this blog

Week 4: Markerless Implementation and Finalisation

Week 3: AR Final Result

Week 10: Project finalization