← Back to Projects

Perpetua Insanus

personal · Unity

Unity C# Game AI State Machines Behaviour Trees A* Pathfinding Inventory System

Trailer

Concept

Perpetua Insanus is a survival horror game in which the player needs to explore its environment to find out not only resources that help him stay safe but also the keys needed to advance.

Level Design

The map in this game is actually just a little of what we wanted it to be. With 3 months of development we had to cut it down so that the quality of the environment would stay as we wanted. With that in mind, we also made the map looping on itself so that it would feel like a real hospital floor and not a linear one.

Player Interactions

In this game the player can interact in several different ways with the environment: dragging doors, drawers, pick ups…

Since more interactions could be added and the game could be expanded, we needed a solid base code in which would allow us to expand without needing to modify the foundation every single time. For that I implemented interfaces from which we could make the dependencies abstract instead of concrete so that any new interactable behaviour only needed to implement the respective interface with their own logic.

Interaction system class hierarchy
PlayerRaycast triggers IInteractable; DragDoor, DragDrawer, and DragRigidBody each implement it, alongside IPickupable for Item.

Inventory

Being able to pick up and store items was one of our most important mechanics: keys, syringes, clues for puzzles, weapons… we had lots of items (and their quantities) and there could be a lot more added, so, just like the player interactions, I implemented a code structure capable of handling expansion without ruining its foundation while also being good performance wise, being approximately O(1) (C# Dictionaries).

Inventory data flow diagram
Inventory holds ISlot, which references IPickupable, implemented by Item.

Hierarchies

Having all these objects and weapons in mind, I designed and implemented hierarchies that allowed for abstract dependencies on interfaces or abstract classes which allowed the expansion of such systems.

Weapons Hierarchy

Weapons hierarchy diagram
Pistol, Shotgun, and Knife all extend a common Weapon base, implementing IInteractable, IPickupable, and IRechargeable.

Since this game was made in Unity Engine, I also wanted to take advantage of some of its functionalities, so the “item hierarchy” was only a class that implemented some interfaces with serialized fields which could be dragged and dropped in the inspector, making it a very generic one.

Item hierarchy diagram
Item implements both IInteractable and IPickupable.

AI

The enemies in this game have their AI implemented in two different ways for academic purposes:

State Machine with Decision Tree:

State machine with decision tree diagram
Patrol, Chase, and Attack states, with a decision tree deciding between ranged and melee attacks.

Behaviour Tree:

Behaviour tree diagram
Behaviour tree covering patrol, chase, and attack decision-making.

These implementations were all based in abstract classes from which the more concrete behaviours can just inherit from them and implement their own concrete logic. This way the code can be reutilized in other projects by being very generic and flexible! (The decision tree used was pretty simple and could be made with an if statement but since I implemented the abstract classes I used them to showcase their potential)

Key Implementation Concepts