Progressive Cube Interaction Game
A simple yet dynamic VR app where cubes change color and provide haptic feedback when touched by a controller. The cube count doubles each time all cubes are activated, making the app progressively more challenging and visually immersive.
The goal of this project was to:
Learn VR app development with the Unity XR Interaction Toolkit.
Explore features such as object interaction, haptic feedback, sound, and dynamic object respawning.
Understand and implement optimizations for scalability in VR environments.
Color-Changing Cubes: Cubes change color from green to pink when touched by a VR controller.
Sound Effects: A sound plays only when a cube changes color.
Haptic Feedback: The interacting controller vibrates upon touching a cube.
Progression: Cube count doubles every time all cubes are activated.
Dynamic Respawn: The level resets with an increased number of cubes after all cubes are activated.
Step 1: Initial Setup
Initial Scene Setup:
Added an XR Rig (from the demo scene in the XR Interaction Toolkit Sample) for player interaction.
Added a Plane to act as the ground.
Added a directional light for global illumination.
Step 2: Creating the Cube Prefab
Cube Design:
Created a basic cube with a Box Collider and an Audio Source.
Added a custom material (GreenMaterial) for the initial green color.
Interaction Script (CubeBehavior):
Implemented a script to handle cube interaction:
Change the cube's color to pink on touch.
Play a sound and trigger haptic feedback.
Step 3: Spawning Cubes Dynamically
Cube Spawner Script (CubeSpawner):
Developed a script to spawn a specific number of cubes in a random 3D area.
Used Instantiate to create cubes and ensure proper placement.
Implemented respawning logic to double the cube count each time all cubes were activated.
Step 4: Adding Haptic Feedback
Integrated haptic feedback using Unity's XR Interaction Toolkit.
Ensured vibration was applied only to the controller that touched the cube, using XRNode detection.
Step 5: Optimizations
Physics: Simplified interaction by ensuring colliders were minimal and efficient.
Rendering: Enabled GPU instancing for cube materials and used simple shaders.
Game Logic: Replaced object destruction with object pooling for better scalability.
Controller Triggering Too Early:
Issue: Cubes changed color when the controller was near but not touching.
Solution: Adjusted collider sizes and ensured precise interaction using smaller colliders.
Performance Slowdown:
Issue: The app slowed down as cube count increased (e.g., at 512 cubes).
Solution:
Enabled GPU instancing for materials.
Increased spawn area to reduce visual clutter.
Implemented object pooling to avoid constant instantiation/destruction.
Haptic Feedback Overlap:
Issue: Both controllers vibrated on interaction.
Solution: Limited haptic feedback to the specific controller interacting with the cube.
Experimentation:
Adjusted collider sizes, audio settings, and haptic intensity to achieve the desired experience.
Iterated on cube placement and spawn logic to balance scalability and immersion.
Problem-Solving:
Used Unity’s Profiler to identify bottlenecks and optimize performance.
Tested and refined each feature in Play Mode and on the Quest 3 headset.
Interaction Design:
Importance of fine-tuning colliders for precise interactions.
Balancing feedback (sound, haptics) to avoid overwhelming the user.
Scalability:
Efficient object management is key to maintaining performance as object counts grow.
User Experience in VR:
Small details like controller-specific haptics and dynamic progression add significantly to immersion.