Building a Virtual Reality Experience: VR Christmas Toss
Virtual reality is a computer-generated simulation or world where your entire view is virtual. We can manipulate this virtual world and do some really amazing things. This is a project I built for the Google Cardboard in the Unity Game Engine, called VR Christmas Toss. In this experience, the user is playing as Santa flying over houses, and they have to try to throw gifts in the chimneys of the houses.
In this experience, the user is in a snowy environment and is challenged to throw presents in the chimneys of the houses. The user has 30 seconds to try to score as many points as possible.
Breakdown of Gameplay
The experience starts in the snowy environment, and the user is shown the time and their score. The user has to try to get gifts in as many houses as they can, but they are only allowed to throw in one gift per house. If they throw more than one gift in a house, only the first gift will count towards their score. The user has 30 seconds to complete this challenge, and when time is up, their score is displayed and the game starts automatically.
Every time the user presses the Google Cardboard button, a gift will be thrown with a little bit of force directly in front of the user. The gifts are also randomized, which means the colour of every gift gets chosen randomly.
There are a lot of houses for the user to try to get the gifts into. When a gift hits the chimney of a house, their score increases and they cannot score anymore points from that house. The colour of the houses are also randomized at the start of every game.
As soon as the game starts, the player moves automatically over the road in the middle of the houses. The user is able to turn their head to be able to view the entire environment of the game.
Gift and Chimney Collisions
In order to be able to score points, both the gifts and the chimneys have mesh colliders. This means that they have an invisible collider around them, which is used to interact with other colliders and detect collisions.
All of the chimneys are tagged “GiftTarget”, and the program is able to recognize if the gift hits a chimney because of this. The section of code means that if the gift’s collider hits another object that is tagged with “GiftTarget” (which is the chimney), it will destroy the gift and the collision box of the chimney. The reason the chimney’s collision box is destroyed is so that the user can’t score more points by throwing presents in the same chimney. 100 points are then added to the score in a different piece of code after this.
Randomizing the Objects
Every time the user clicks the Cardboard button, a random gift is chosen. This works through Unity’s built in “random.range” function. This picks an element of an array at random, which means choosing a random integer between 0 and the maximum index value, which is the length of the array minus one. The same thing is done for the houses, for which the colours appear randomly at the start of every game.
If you enjoyed this article:
- share it with your network
- follow my Medium and LinkedIn to stay updated with my progress in virtual and augmented reality!