Posted March 03, 2025 by Michael kronfeld
#Cinemachine #mesh generation
This is the second devlog for Subject 13. In this devlog, we will be covering the progress made since the last devlog. This will entail the creation of a dynamic mesh for the player's soft-body, player movement, as well as the current camera implementation. As a recap for anyone who didn't see the first devlog, the general premise of this game is that you are a lab-made slime that needs to escape, you can flip your gravity, jump and shrink where the objective is to evade capture and escape the lab. Last devlog covered the creation of the soft-body itself, this devlog will follow on from there.
While the physics behind the soft-body system were covered in the previous devlog, one of the major issues was the lack of a clear visual representation past the vertices of the soft-body. The problem was that without a proper mesh, the soft-body was simply a collection of rigid-bodies connected by springs. To address this, I needed a way to generate a mesh dynamically at runtime, connecting all of the soft-body points and ensuring that it smoothly deforms with the soft-body’s movement/collisions.
The approach I chose involves procedurally generating a mesh each frame, with vertex positions updating in real-time to match the soft-body’s structure. The vertices for the mesh are formed using an interpolated set of points linking each point of the soft-body's perimeter with the central vertex. Without any interpolated points, the mesh would look too triangulated (Figure 1 - 1 step). To solve this, I used a Catmull-Rom spline. This calculates additional points between the rigidbody segments, thus smoothing the outer edge of the shape. These vertices are then connected using a triangulation process to form one continuous face (Figure 1 - 5/25 steps).
Unity does not have built-in soft-body mesh generation, so the process of generating this mesh can be broken down into the following steps:
With the mesh generation working, the next major component was movement. The soft-body movement system is physics-driven, meaning forces are applied to the Rigidbody2D
components to simulate movement rather than directly setting positions. This allows for a more natural and dynamic feel.
The movement system consists of several key mechanics:
One challenge was ensuring smooth control while keeping the soft-body's movement responsive. Tuning values like friction, acceleration, and max velocity was crucial in making the movement feel satisfying. Currently, the system works well, but adjustments will be needed as new mechanics are introduced.
To improve how the player interacts with the game world, a Cinemachine camera system was implemented. The goal was to create a smooth-follow camera that tracks the player's movement without feeling too rigid or too loose.
The key features of the current camera system include:
While the system works well for now, there are several planned improvements:
This current system, along with the planned changes, will hopefully improve the player's navigation skills and awareness. However, further refinement will be needed to perfect the system and make it intuitive and fun to use.
This devlog now concludes the majority of the work on the player movement and generation systems (other than the collision detection issues from the first devlog). The next steps for development are outlined below. These items represent upcoming features, though they may not necessarily appear in the very next devlog.
Thank you for reading through this second devlog! There's still a lot more features and mechanics to come, as listed above. If you have any feedback, comments, or suggestions, please leave a comment. I'll see you in the next devlog.