Devlog #2: Dynamic mesh creation, Movement & Cinemachine


Introduction

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.

Dynamic Mesh Creation

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:

  • Defining the vertices: Each segment of the soft-body has a corresponding vertex in the mesh, with interpolated points added between the vertices for smoother transitions.
  • Updating vertex positions: As the soft-body moves, the vertex positions are updated each frame to reflect the real-time deformation.
  • Triangulating the mesh: The vertices are connected to form a continuous surface, ensuring stability and a seamless appearance.
  • Applying UV mapping: A texture can be mapped onto the dynamically changing shape to maintain a consistent visual appearance.
  • Rendering the mesh: The generated mesh is applied to a MeshFilter and rendered using a MeshRenderer.

Figure 1
Figure 1 - Showing the different levels of smoothing on an 8-vertex soft-body

Movement

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:

  • Basic movement: The player can move left and right by applying impulse forces in the respective direction. Friction is used to gradually slow down movement when no input is detected.
  • Jumping: The player can jump if they are in contact with the ground. A force is applied to all segments of the soft-body to create a smooth and consistent jump motion.
  • Gravity flipping: The gravity direction can be flipped, allowing for movement on ceilings and walls. When activated, forces are applied upward instead of downward.
  • Shrinking: The player can shrink, which affects the lengths of the connecting springs and could be useful for squeezing through tight spaces.

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.

Mesh deforming to diffrent states of collison
Mesh deforming, bouncing, shrinking and flipping gravity

Cinemachine Camera System

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:

  • Dead zones: A small area in the center of the screen where the player can move slightly without triggering camera movement, reducing unnecessary camera shifts.
  • Soft follow: The camera smoothly follows the player using position damping, preventing sudden jerks and making movement feel more natural.

While the system works well for now, there are several planned improvements:

  • Refining dead zones: Tweaking the size and shape of the camera dead zone to ensure it provides the right balance of camera movement, freedom and responsiveness.
  • Level panning shots: Implementing cinematic camera movements upon entering a new level to provide a brief overview of the environment.
  • Dynamic zooming: Adjusting the camera zoom based on player speed or environmental factors to enhance the overall feel of the game.
  • Predictive movement tracking: Adjusting the camera to look further ahead in the direction the player is moving, giving better visibility of upcoming obstacles.

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.

Cinemachine boundies overlay

Future Development

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.

Things to Come:

  • Menu systems
  • Hazards and dangers (turrets, spikes, cameras, lasers, etc.)
  • Puzzle systems (buttons, weighted buttons, levers, timed events)
  • Level design and asset creation
  • Music and SFX
  • Saving and loading

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.

Leave a comment

Log in with itch.io to leave a comment.