Soft-body physics
This is my first devlog for my university project, Subject 13. In this devlog I will be going over the creation of the players soft-body, any known issues and potential fixes that still need to be implemented, then I will briefly talk about the next steps for this project. First for some context, as to the plan and direction of this game, the main character is a soft-body slime that has been created in a lab, you've now escaped your containment and now need to escape the lab. This will entail evading dangers, using your shrinking, jumping and gravity-flipping abilities to evade the hazards and escape the lab.
The basis of the game revolves around the soft-body nature of the player, and its ability to dynamically deform to external factors, such as the players movement, gravity and collison with other objects.
Soft-body creation
Unity (the game engine for this project) wont natively create a soft-body object, this means that we need to create a custom soft-body system for our player. The widely accepted method of creating a soft-body object is by using multiple rigid bodies held together with springs to create the illusion of a soft-body. Whilst this is the easiest and fastest method of creating a soft-body, it does present several major issues that we will discuss later in this devlog, for now we will focus on the creation of the soft-body itself.
The aproach I've decided to take with my soft-body is to have it generated at run-time as opposed to having a predefined soft-body. This provides me with several advantages over having a pre-made one, the biggest of which is the flexability to easily make changes to the players soft-body with minimal effort after the inital set up of the script that generates it. The variables that I can control with my soft-body generation script are as follows:
- Segment count
- Radius of the circle
- The mass of each segment
- Spring frequancy
- Spring daming ratio
These controllable variables allow me to create a wide range of unique soft-bodies, which hopefully will allow for easier tweaking of the soft-body later in the development process. The creation of the soft-body can be broken down into several steps. The distribution of the desired number of points onto a circle, next the placing of the segment prefab (a game object with a 2D rigid-body and 2D circle collider) at each of the points that have just been calculated and then finally linking all of the generated segments to every other segment, and the center of the soft-body with springs. Below are images showing the soft-body reacting to diffrent types of collision.


Known issues
There are several issues with this current implementation of the soft-body physics, firstly since the springs are the only thing that hold the segments in a circle shape it is possible and even likely that when you hit a surface with any sizable amount of force that the circle will simply collapse. This happens because all the springs can still maintain their required distances just by offsetting on a singal axis(figure 1). This effect can be mostly mitigated by manually setting the center of the soft-body circle to the average position of all of the segments, thus always keeping it roughly centered and allowing the center springs to push against the segments and the center thus making a total collapse of the soft-body circle a lot harder to achieve. The next most pressing issue with how the current soft-body system works is the collisons, since each segment is generated as a circle with a circle collider, there is nothing linking the segmets together other then the springs. Since the springs don't have any collision properties, this means if there is a small enough object that can fit between two segments it'll simply pass straight through the soft body(figure 2). This issue is a lot harder to fix since there is no easy work-around to it. Currently, I don't have a system in place to deal with this, but one potential fix is too use an Axis aligned bounding box (AABB), for each wedge of the circle to tell if an object has passed into the soft-body as well as how far its passing into it and the normal of the collision, all of which will be critical information when resolving the collison.


Future development
The game (if you can even call it that at this point) still has lot of content to be added. The rough development plan for this project will be bi-weekly devlogs (although this may change) that will cover progress made since the last devlog. As for what is still needed to be added its as follows:
- A dynamic mesh renderer that can handle the dynamic creation of soft-bodies that have varying segment counts
- Soft-body collisions (as discussed earlier)
- Gravity-flipping mechanic
- Refining the movement system
- Camera tracking to the player (likely done using Cinemachine)
- Menu systems
- Hazards and dangers (turrets, spikes, cameras, lasers ect)
- Puzzle systems (buttons, weighted buttons, levers, timed events)
- Level design and asset creation
This list is likely to change, have items added and/or removed as this project is still very early in development, but it should provide a good idea as to the direction that the game will be heading.
If you've made it this far thank you for reading all the way through, please do leave a comment with any thought or suggestions you may have for the project and I'll see you in the next devlog.
Subject 13
The experiment was a success. The containment was not.
Status | In development |
Author | Michael kronfeld |
Genre | Puzzle |
Tags | 2D, Side Scroller, softbody, Unity |
Leave a comment
Log in with itch.io to leave a comment.