project showcase

TennisStrike

Developed a tennis game set in a virtual stadium where random balls appear, and players hit them with a racket, enhancing hand-eye coordination in a fun setting.
Project Type
Classroom Project
Timeline
2023
Developer
Solo Developer & Designer
Further Demonstration
Code Available Upon Request

VR Racing App

Developed a Virtual Reality racing app, incorporating 3D physics and immersive gameplay to create an engaging and interactive driving experience.

scroll

Project Overview

Scope

Concept: 

Developed a virtual reality tennis game using Unity, where players hit randomly generated tennis balls with a racket in a virtual tennis stadium. By simulating a realistic tennis environment, the application makes physical activity enjoyable and accessible, promoting fitness through interactive gameplay.

Technical:

Game Initialization and Best Score Display

Implemented scripts to manage the game's introductory sequence, displaying the player's best score and handling scene transitions. This feature enhances user experience by providing immediate feedback and a sense of progression.

Code Snippet:
1public class IntroScript : MonoBehaviour
2{
3    public GameObject BestScoreDisplay;
4
5    void Start()
6    {
7        getBestScore();
8    }
9
10    void getBestScore()
11    {
12        // Fetch the best score from PlayerPrefs
13        ApplicationData.Best = PlayerPrefs.GetFloat("BestScore", 0);
14
15        if (ApplicationData.Best > 0)
16        {
17            BestScoreDisplay.GetComponent<TMPro.TextMeshProUGUI>().text = ApplicationData.Best.ToString("P1");
18        }
19        else
20        {
21            BestScoreDisplay.GetComponent<TMPro.TextMeshProUGUI>().text = "First Time player, no best score yet!";
22        }
23    }
24
25    void Update()
26    {
27        // Start game when the user presses the trigger or 'B' key
28        if (OVRInput.Get(OVRInput.RawButton.LIndexTrigger) ||
29            OVRInput.Get(OVRInput.RawButton.RIndexTrigger) ||
30            Input.GetKeyDown(KeyCode.B))
31        {
32            SceneManager.LoadScene("Workout_Loading");
33        }
34
35        // Developer cheat to reset best score
36        if ((OVRInput.Get(OVRInput.RawButton.X) && OVRInput.Get(OVRInput.RawButton.A)) ||
37            Input.GetKeyDown(KeyCode.C))
38        {
39            PlayerPrefs.SetFloat("BestScore", 0f);
40            SceneManager.LoadScene("Workout_Intro");
41        }
42    }
43}
44
  • The IntroScript class handles the game's introduction by displaying the best score and transitioning to the main game scene upon user input. It retrieves the best score using PlayerPrefs and updates the UI accordingly. The script also includes a developer shortcut to reset the best score.

Ball Collision Detection and Scoring System

Created collision detection between the racket and the tennis balls to track successful hits. Implemented a scoring system that updates the player's score, provides haptic feedback, and manages game progression.

Code Snippet:
1public class CatchMeScript : MonoBehaviour
2{
3    private bool FirstHit;
4
5    void Start()
6    {
7        FirstHit = false;
8    }
9
10    void OnCollisionEnter(Collision collision)
11    {
12        if ((collision.gameObject.CompareTag("Rrack") || collision.gameObject.CompareTag("Lrack")) && !FirstHit)
13        {
14            FirstHit = true;
15            ApplicationData.NumHit++;
16            // Hide the flying ball and show the caught effect
17            flying.SetActive(false);
18            caught.SetActive(true);
19
20            // Provide haptic feedback
21            if (collision.gameObject.CompareTag("Rrack"))
22            {
23                OVRInput.SetControllerVibration(1, 1, OVRInput.Controller.RTouch);
24            }
25            else
26            {
27                OVRInput.SetControllerVibration(1, 1, OVRInput.Controller.LTouch);
28            }
29            Invoke("StopVibration", 0.1f);
30            Invoke("DestroyCaughtBall", 2f);
31        }
32    }
33
34    void DestroyCaughtBall()
35    {
36        gameObject.SetActive(false);
37        // Check if the game is over
38        if (ApplicationData.NumShot >= ApplicationData.NumMax)
39        {
40            Invoke("Endgame", 3f);
41        }
42    }
43
44    void Endgame()
45    {
46        float currentScore = ApplicationData.NumHit / ApplicationData.NumShot;
47        if (currentScore > ApplicationData.Best)
48        {
49            ApplicationData.Best = currentScore;
50            PlayerPrefs.SetFloat("BestScore", ApplicationData.Best);
51        }
52        SceneManager.LoadScene("Workout_Endgame");
53    }
54
55    void StopVibration()
56    {
57        OVRInput.SetControllerVibration(0, 0, OVRInput.Controller.LTouch);
58        OVRInput.SetControllerVibration(0, 0, OVRInput.Controller.RTouch);
59    }
60}
61
  • The CatchMeScript class detects collisions between the tennis balls and the player's racket. Upon a successful hit, it increments the hit count, provides haptic feedback through the controllers, and manages the destruction of the ball object. It also checks if the maximum number of shots has been reached to transition to the endgame scene.

Impact

  • Encouraging Learning: The game serves as an interactive tool for improving motor skills and hand-eye coordination. By simulating realistic tennis gameplay, users can practice and develop their reflexes and timing in a fun and accessible way.
  • Immersive Gameplay: The immersive tennis stadium environment and the challenge of hitting randomly generated balls keep users actively engaged. Features like score tracking, best score display, and haptic feedback enhance the gaming experience, motivating users to improve their performance.
  • Innovation: This project demonstrates how virtual reality can be leveraged to create engaging physical activity experiences. It highlights the potential of VR technology in promoting fitness and sports training, offering an innovative resource that can be utilized in educational settings, sports facilities, and home entertainment.

Heading

Client
Apple
Date
November 2023
Role
Designer & Developer

Team section

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse tincidunt sagittis eros. Quisque quis euismod lorem.