Undersea Explorers

Screenshot 2023-04-30 at 00 27 21

Welcome to my tech demo :). A procedurally generated map where AI agents move and behave according to their agenda/behaviour tree.

Overview

This project is made as part of ECS7016P - Interactive Agents and Procedural Generation Module. This unity coursework procedurally generates underwater caves and simulates agents navigating through these caves. The cave generation is based on cellular automata, and the navigation and behaviour of agents are achieved using MovementAI and NPBehave packages, respectively. The project is composed of two main components: the underwater cave generator and the agents.

Set-Up

To set up the project, follow these steps:

  1. Download the project file from the GitHub repository. If you are not already on the repository page, use the link provided in this README.md file.
  2. If the downloaded file/folder is compressed, unzip it.
  3. Open Unity and ensure that you have the compatible version mentioned above.
  4. Open the project folder (ECS7016P_TechDemo > Interactive_Agents_CW_UnderSeaExplorers_Huseyn_Gorbani) with Unity where you have saved the downloaded file.
  5. Within the project folder, navigate to the "Assets" folder and click on the "Main.unity" file.
  6. You should now see the project hierarchy, similar to the picture below.

Screenshot 2023-04-30 at 00 22 02

Cave Generation

The Underwater Cave system is generated using four scripts:

  1. UnderwaterCaveGenerator.cs
  2. MeshGenerator.cs
  3. CustomSpawner.cs
  4. CaveConnector.cs. These scripts work together to create a procedurally generated underwater cave environment.

Please Note: During the development of MeshGenerator.cs and CaveConnector.cs, the repository of Sebastian Lague (available at: https://github.com/SebLague/Procedural-Cave-Generation) was studied and re-used partially to achieve a more realistic cave.

UnderwaterCaveGenerator.cs

Inside the unity project, located in the Generators folder (Assets > Generators > UnderwaterCaveGenerator.cs), this script is responsible for generating the cave structure using a cellular automata approach to manage the overall map generation and game map logic. It initialises the cave with random tiles (soil or water) and iteratively smooths the cave structure based on the surrounding tiles. The generated cave structure is represented as a grid of integers, where 0 represents water, and 1 represents soil. Additionally, it handles the placement of prefabs, including agents (Diver, Mermaid, and Shark) and the Treasure Chest.

MeshGenerator.cs

Inside the unity project, located in the Generators folder (Assets > Generators > MeshGenerator.cs), this script generates the mesh for the cave environment based on the grid created by the UnderwaterCaveGenerator.cs script. It processes the grid to create vertices and triangles in both the soil and water layers. This script handles the generation of the mesh for the water layer, which is placed slightly below the soil layer.

CustomSpawner.cs

Inside the unity project, located in the Generators folder (Assets > Generators > CustomSpawner.cs), this script is responsible for spawning MovementAI obstacle game objects based on soil cells within the generated cave environment. The script takes the generated grid as input and places obstacle objects at suitable locations, but not for every soil cell; instead, it places them only in every 10th soil cell. These obstacles are used to establish hiding behaviour for the agents, utilizing the MovementAI library.

CaveConnector.cs

Located in the Generators folder (Assets > Generators > CaveConnector.cs), this script identifies and connects separate cave rooms generated by the cellular automata process. It identifies rooms by performing a Flood-Fill algorithm and then finds the closest rooms to each other. Finally, it creates corridors between the rooms to connect them, ensuring that the whole cave system is interconnected and navigable for the agents.

Together, these four scripts work in tandem to create a procedurally generated underwater cave environment, complete with interconnected rooms and various agents and objects placed within it.

Agents

Diver

Goal: Seek and Find the Treasure Chest. Behaviours:

  • When in danger,
    • place a limited number of Sea Mines (up to 5) to kill the chasing Shark.
    • Evade from the Shark.
    • Hide from the Shark.
  • Get distracted by the Mermaid, follow it and temporarily forgetting about the Treasure Chest.
  • Seek and attempt to find the Treasure Chest.

Screenshot 2023-04-30 at 00 29 46

Mermaid

Goal: Distract the Diver from the Treasure Chest and potentially lead them closer to the Shark by interposing between them. Behaviours:

  • Look for the Diver to distract them from the Treasure Chest and lead them towards the Shark.
  • Move randomly around the Treasure Chest.

Screenshot 2023-04-30 at 00 29 27

Shark

Goal: Protect the Treasure Chest from Diver Behaviours:

  • Chase and attempt to kill the Diver if the distance from the Treasure Chest is less than 150% of the Shark's distance from the Diver
  • Protect the Treasure Chest by patrolling its vicinity.

Screenshot 2023-04-30 at 00 30 04

Other In-Game Objects:

Treasure Chest

Screenshot 2023-04-30 at 00 31 42

Sea Mine

Screenshot 2023-04-30 at 00 33 13