The Mechanic's Knot
About
The Mechanic's Knot was my first attempt at accurate rope physics simulation, which in turn necessitated the implementation of an Entity-Component-System (ECS) architecture to ensure optimal performance
Project Info
Role: Gameplay and Design Programmer
Team Size: 1
Time Frame: 10 Weeks
Engine: Unity (C#)
Introduction
The mechanic's Knot features physics-accurate ropes where the player can form knots around nodes (cogwheels) to trigger their rotation in a specific direction. The level design takes advantage of the rope's physical properties and the mechanics that emerge from the interactions and combinations of nodes, creating engaging and dynamic gameplay.

The rope physics was simulated using Verlet integration, chain constraints and radius collision checks. Unity's line renderer feature was used to render the rope texture. Instead of undoing or resetting, I introduced a knife tool which allows the user to slice anywhere on the rope if not required.

In order to parallelize the simulation load of the ropes, I implemented the job system offered through the ECS architecture. This led me to learn the rest of what ECS offered and tried my best to implement each of the feature into this project.
Rope Physics
The rope simulation uses Verlet integration to update the positions of a set of points. To keep the rope's structure intact, constraints are applied multiple times at fixed intervals, ensuring the particles stay connected in a seamless chain. The collisions are performed with a simple radius distance check between the points on the rope and the nodes.

The most performance heavy section of the simulation was the multiple execution of the constraints on all points of the rope. Higher numbers caused the rope to be less stretchy and more rigid. Since my project did not require a highly rigid rope, I settled on 5 iterations on mobile devices and 10 iterations on desktop. But after implementing ECS I was able to set higher values without any hiccups.
Node Mechanics
I tried implementing the node's rotation by applying a constant rotation once a rope knot has been formed. This in-turn caused an unrealistic rotation of the nodes in contrast to the realistic rope physics, thus the node rotated at a different rate to what the rope intended it to.

This issue was fixed by averaging the angle created by the previous and current position of all the colliding points of the rope on the node. The average provided an approximate of the rope's speed with minimal error, which was then applied to the nodes. I wrote a test script which abruptly changed the rope's speed, and the node matched the rope.

Another interesting mechanic was being able to cause a deadlock of the nodes when a node is forced to rotate in both directions. This deadlock should result in the stoppage of the movement of all the connected ropes and nodes.
Abrupt Rotation
Deadlock
Entity Component System (ECS)
Though I had some experience in ECS this was my first attempt at fully implementing the Data Oriented Programming architecture in a project. I used Unity’s Data-Oriented Technology Stack (DOTS) to build high-performance systems, simulate complex physics and handle data efficiently. By using the Entity-Component-System (ECS) paradigm, I created a modular and scalable architecture that’s optimized for memory usage and parallel processing. Almost every part of the game - except the UI - is built using ECS for maximum performance.

Leveraging Data-Oriented Architecture, I parallelized the rope simulation systems to achieve high performance. Collision checks were the second highest in regard to performance impact, since you have to check all the points of every rope with each node. Unlike applying constraint which required the entire rope chain data on each thread, the collision only required each point data. Thus, I was able to run the collision check of a batch of points from all ropes on each thread. This optimization enabled the real-time instantiation and simulation of a large number of ropes, even on lower-end devices, ensuring smooth and efficient execution.
Play "The Mechanic's Knot" on itch.io     or check out the repository at github.com