Skip to content

HW 6: VR Game

This assignment is to complete a VR Game, titled "Beet Saver" (a parody of Dr. Wang's favorite VR game, Beat Saber).

You play as a humble beet farmer, sharing the gift of root crops with the world. However, one day, one of your chickens goes rogue and evolves into a sentient higher life-form! Can you save the beets while dodging the bombs thrown at you by this fiendish fowl?

Watch the video below to see an example of the completed game:


Instructions

Purpose: The goal of this homework is to demonstrate using VR interactions, collision triggers, and connections between multiple scripts in Unity.

Task: Most of the game has been completed for you; however, you will need to follow the instructions to finish the remaining functionality. The game is missing interactions and key scripts that tie it together. Your goal is to make it behave like shown in the video.

Steps: Start by downloading the starter project. Unzip it into a location of choice, then open it with Unity Hub. You can select any version of Unity that is 2021.3.29f1 or above (agree to the prompts to migrate/upgrade it if needed).

Once the project is opened, go to the Project View and open Assets > Scenes > StartScene. This is the main menu of the game. You should complete the SceneSwitcher.cs file and set the two buttons in the menu to load the next scene or quit the application.

Next, in the Project View, open the GameScene (in the same location as StartScene). This is the main game. In the Hierarchy, you will find a few objects of interest:

  • EvilChicken: The main villain of the game. Will randomly throw beets and bombs at the player.
  • Beet Box: Beets that are put in the box add to the game's score. This GameObject also contains the game's UI and the game over menu (important for later).
  • Beet: A disabled (leave it like this!) GameObject that serves as a "template" beet to be thrown by the chicken.
  • Bomb: A disabled GameObject that serves as a template bomb to be thrown by the chicken.

Your first task is to make the beet and bomb grabbable. Right now, the player cannot interact with them. You will need to add the correct components to both objects. If you need a refresher on how to do so, consult Lab 4.

Next, you need to make the evil chicken launch objects by completing the EvilChickenBehavior.cs script. See the next section for details.

After this, write the methods in the ScoreKeeper.cs script, and then complete the BeetBehavior.cs script to implement the beet's behaviors.

You should test it on the headset as well to make sure you have implemented everything correctly! It should look like the provided video.

Scripts to Write/Complete

  1. SceneSwitcher.cs

    This script will be used by the buttons in the game to switch scenes. (Make sure the scenes are properly set in the build.)

    • NextScene() - Switch the game to the next scene.
    • PrevScene() - Switch the game to the previous scene.
    • QuitApp() - Quits the application.
  2. EvilChickenBehavior.cs

    The public variables have been set for you. Look over these first to understand what each one does. Then write the behavior of the chicken in the Update() method. The chicken should throw an object every throwDelay seconds.

    The object may be a either beet or a bomb based on the bombProbability. This is done by getting a random value and comparing it against the probability of throwing a bomb. You must use the Instantiate() function to create a new beet or bomb based on the beet and bomb GameObject variables.

    After instantiating a new object, it must be set to active and then thrown at the player. An example on how to create and launch objects is provided on Slide 32 of the Unity Interaction lecture slides. You should get the Rigidbody component on the new object and then use the AddForce() method to launch the object (see the slides for details). Use the provided ComputeThrowVector() method to determine the force required.

    • Update() - The difficulty increase has been coded for you. You may use this as an example of how to make thing happen after a certain period of time. You will need to increment the timeSinceLastThrown and then check it to see if it has passed the throwDelay.
  3. ScoreKeeper.cs

    This script will keep track of the current score and state of the game. Will be used by BeetBehavior and BombBehavior to add to the score and end the game. The public variables should already be set. You will need to use them in the two methods:

    • ScoreBeet() - Increase the score by one and play the pop sound effect. (Hint: PlayOneShot will play a specific AudioClip)
    • GameOver() - Enable the Game Over menu, disable the evil chicken behavior, and play the explosion sound effect.
  4. BombBehavior.cs

    This script is provided for you as an example. Reference it when writing your BeetBehavior.cs script.

    • OnCollisionEnter() - Checks collision with both the player and beet box. If it collides with either, triggers a game over on the scoreKeeper. The bomb is destroyed if it collides with any object.
  5. BeetBehavior.cs

    This script is attached to the beet GameObject and defines how the beet behaves. First off, each beet has a lifespan (default 10 seconds). After it passes this lifespan, it is destroyed. Second, if the beet collides with the beet box object (with tag BeetBox), then it should increase the game's score. The beet should also be destroyed in this case.

    • Update() - Increment the timeSinceSpawned variable and check to see if it has surpassed its lifespan. If so, Destroy() the gameObject that this script is attached to.

    • OnCollisionEnter() - You need to check if the beet has collided with the beet box object (tag BeetBox). If so, call the ScoreBeet() method on the scoreKeeper variable and also destroy the gameObject that this script is attached to.

Submission

Go to the folder containing your Unity project. You can use Unity Hub to quickly do so.

Open the folder corresponding to your project. Inside, you should see a lot of subfolders, including Assets, Library, etc.

Create a zip file containing only the Assets, Packages, and ProjectSettings folders. The other files are generated by Unity and not needed for submission.

Submit this zip file to Canvas.

Grading

You will be graded based on your completion of the four scripts and the required functionality of each of the methods. You should have a finished, fully-playable game at the end of the assignment!

Canvas will have a full rubric when graded.