Aliens V/S Laser Knights

Assignment 02 of 3D Games Programming | MSc Game Development (Programming) | Kingston University

Platform: Virtual Reality with Brain-Computer Interaction

Engine: Unity

Team Size: 1

Role: Lead Programmer

Roles and Responsibilities

  • Developed an Emotiv EEG powered game that seamlessly integrates virtual reality and brain-controlled computer interaction, offering a unique and immersive gaming experience akin to science fiction.
  • Implemented a training mechanism and input system using Emotiv's Cortex API to enable users to play the game with their thoughts and familiarize themselves with mind-machine interactions.
  • Utilized Unity's Entity Component System and Data-Oriented Technology Stack to optimize the efficiency of simulating in-game enemies.

Overview

While previous projects utilizing similar technology have been demonstrated on Emotiv's official YouTube channel, many exhibit a lack of cohesion in terms of both scope and scale.

Distinguishing itself from these instances, this project stands out due to its incorporation of Virtual Reality (VR) technology. This integration aims to deliver a gaming experience that authentically embodies a futuristic paradigm.

Consequently, the central challenge inherent in this initiative has been the seamless amalgamation of these two technologies, thereby producing a solution that transcends the realm of science fiction, a concept that has captivated imaginations for decades.

Assets Used

User Instructions

Users must undergo training to proficiently use their minds for interaction in the game. Simultaneously, the system adapts to each user's unique brain patterns, enhancing player control precision.

To streamline this process, my solution incorporates an in-game training level. This enables users to familiarize themselves with the system in a context aligned with the natural gameplay of the project.

Emotiv's Cortex API enables the training scene with a user interface similar to the BCI application, offering immediate feedback and guiding users on strategy adjustments.

As a rule of thumb, the following two strategies are recommended by Emotiv:

  • Each action produces a distinct pattern from every other action.
  • The visualizations should be easy to reproduce each time.
User Instructions

Entity Component System to optimize Enemy Behaviour

This project strategically employs Unity's Entity Component System (ECS) and Data-Oriented Technology Stack (DOTS) to enhance the efficiency of simulating in-game enemies.

Given the game's classification within the bullet-hell genre, the scene accommodates a considerable number of enemy objects, often numbering in the hundreds simultaneously.

The inherent complexity of managing numerous entities in conjunction with the immersive Virtual Reality environment introduces the potential for disorienting lags during gameplay.

To address this challenge, the utilization of ECS and DOTS serves to optimize the processing and rendering of enemy entities, mitigating performance bottlenecks and ensuring a smoother and more immersive gaming experience for the player.

Design Patterns for enhanced Architectural Solutions

In order to facilitate interaction between the player's monobehaviours and the ECS in the scene, I established singleton entities that autonomously update based on the player's game state. These entities encompass aspects such as the player's transform, health, etc. A script manages the bidirectional information flow between the traditional monobehaviour architecture and the ECS, establishing a cohesive hybrid framework for interaction.

Singletons, in conjunction with the flyweight pattern, efficiently cache diverse enemy ship prefabs, projectiles, and particles within a unified entity. This not only mitigates memory consumption but also establishes a centralized referencing method for enemy entities.

I considered object pooling for enemies but deferred due to the optimized ECS instantiation pipeline, prioritizing simplicity and time considerations. It remains a potential enhancement for future frame-rate optimization.

Cortex API Classes

The EmotivUnityItf.cs is the primary liaising class between the Cortex Unity plugin and the Cortex framework for interactions. However, it is noteworthy that the plugin, in its current state, is not entirely production-ready and requires enhancements. As such, substantial effort was directed towards establishing the requisite functionality for the training interface. Fortunately, the plugin provided a helpful framework, saving us from having to build everything from scratch.

The EmotivTrainingInterfacer.cs is the class responsible for handling the training interface of the game. Its functions encompass the initialization of the Emotiv system, management of callbacks, subscription to data streams, and subsequent UI updates.

The EmotivGameplayInterfacer.cs class is designed for gameplay and shares most features with the training interfacer. Unlike the training aspect, it focuses solely on processing player input for gameplay by subscribing to the 'Mental Command' data stream.

ECS System Archetypes

In my project, systems handle entity creation and updates. If instantiation parameters rely on update systems, they're added to a DynamicBuffer in the spawner during the update loop. Entities are then instantiated in the next update of the InitializationSystemGroup, followed by buffer clearance.

For example: the OrbitSpawnerSystem.cs creates Orbits, leading to the spawning of Satellites by SatelliteSpawnerSystem.cs. The positions of satellites are managed by the SatelliteOrbitingSystem.cs, within which when conditions for laser spawning are met, a MissileSpawnElement is added to the buffer. The MissileSpawnerSystem.cs subsequently spawns the lasers, and their positions are updated by the LaserLocomotionSystem.cs.

Two crucial systems include CollisionEventsSystem.cs and TriggerEventsSystem.cs. These classes play a pivotal role in managing collisions between player and enemy entities.

Performance

By leveraging ECS, Unity efficiently manages the instantiation, updates, and interactions of numerous objects in the VR environment. The screenshot serves as a visual testament to the effectiveness of Unity's ECS in handling the computational demands of the project, ensuring a smooth and immersive user experience.

Performance

© Copyright Jasfiq Rahman 2024

Icons by Icons8 and Flaticon.