A2 - Bowling in VR

Bowling in VR

Goals

  • Creating a simple bowling hall
  • Grabbing the ball from a socket
  • Physics of Pins including collisions
  • Scoring and display
  • Physics Material
  • Interactive Audio

Solution

Here you can find the solution app. Download the .apk file and test it in the Quest for reference.

Additional Material

Point List (max 5 points)

  • App runs in VR (1 point)
  • Ball can be thrown and slips nicely (1 point)
  • Pins fall and make proper sounds (1 point)
  • Scoring board counts (1 point)
  • Extra Tasks

Instructions

Setup VR

  • Do not remove ray interactors

Create App

Make World

  • Add ground plane. Make it long in z direction.
  • Add two lane boundaries with cubes
  • Add some colors

Make Hands

  • Make Cube, set color and size
  • Remove box collider
  • Turn cube to prefabs ‘Hands’
  • Put hands as Model Prefab to Left/RightHand Controller

Make Ball

  • Make Sphere, set size and color
  • Add Rigidbody and enable gravity
  • Add XR Grab Interactable
  • Make prefab

Distance Grab and Throw Ball

  • RightHandController -> XR Ray Interactor -> Enable Force Grab
  • Test grab with ‘grip’ button and throw ball
  • Button can be changed in RightHandController -> XR Controller (Device-based) -> Select Usage

Direct Grab

  • Remove from LeftHand Controller: XR Ray Interactor, Line Renderer, XR Interactor Line Visual
  • Add to LeftHand Controller: XR Direct Interactor
  • Add to LeftHand Controller: Sphere Collider, set radius to 0.2, and enable ‘Is Trigger’
  • Test direct grab
  • (optional) Enable XR (Ray/Direct) Interactor -> Hide Controller on Select

Make Pin

  • Make Cylinder, set size (e.g., 0.08, 0.2, 0.08) and color
  • Add Rigidbody, set mass
  • Make prefab
  • Place ten pins

Make Table for the Ball

  • Make Cube, place it at the side of the lane
  • Place SocketInteractor on table: Create empty GameObject, add XR Socket Interactor, add Sphere Collider (enable is Trigger)
  • Set Ball to XR Socket Interactor -> Starting Selected Interactable. The ball needs to be in the scene, not only a prefab.

Add Sounds for Pins

  • Add to Pin Object: Audio Source Component and add pin impact sound file, disable ‘Play on Awake’
  • Add to Pin Object a script “Impact Sound”
  • Create variable AudioSource and connect component to script
  • OnCollisionEnter play sound, (optional) use velocity to randomize volume and pitch

Add Physics Material to Ball

  • Create Physics Material. Name it ‘Slip’.
  • Set Dynamic and Static Friction to 0.1. Friction Combine to Minimum. Bounciness to 0.3.
  • Drag Physics Material to Ball

Add Scoring Board

  • Add XR -> UI Canvas, Scale Canvas to (0.01,0.01,0.01), place canvas above pins

  • Add Text (Text Mesh Pro) to Canvas as a child. Name “Score”.

  • Add Script “Manage Score”. Open for edit

  • Add public function ‘IncreaseScore’ for counting the points

  • Add function ‘UpdateText’ for changing the Text in the Canvas (use score.ToString())

  • Add Script “PinFalling” to Pin

  • Add “using UnityEngine.Events;” to header

  • Create Unity Event

  • Invoke Unity Event on collision and if the pin is standing. (This is somehow inaccurate as the pin might not fall).

  • In Unity Editor, add Score to Pins' unity event

Extra Tasks

  • Add Background sounds, textures to objects (0.5 points)
  • Spawn new bowling ball in Socket when the ball is removed (0.5 points)
  • Add sounds to bowling ball (1 point)
  • Add text when all pins fall over and reset pins (1 points)
Previous