Fast Blob Physics
Fast Blob Physics
Grant Kot In this tutorial, we are going to explore how to create a blob similar to the main character Gish in the video game Gish. Ill also detail a simple collision handling system for multiple blobs that is both fast and stable. Usually blobs are simulated with a combination of edge springs and internal springs to keep their shape. In most of these setups, there will be a point where the blob has deformed so much that the mesh will invert and get stuck. Im going to show you how you can get rid those internal springs, and actually end up with something way more stable. Here is the formula for calculating the area of a polygon:
We want our blobs to behave as if theyre filled with some kind of incompressible fluid. The area of the polygon should stay the same even if the vertices move around. I am going to make the assumption that the pressure force is going to move each vertex the same distance h along its normal if the current area of the polygon is not equal to the target area.
When I plug those terms into the polygon area formula and set it up so that it will equal the starting area, I will get this equation:
So right now, we have a quadratic equation for h but in its current format its a bit awkward to work with. In the next steps, well shuffle things around a bit so that we will be able to solve for h using the quadratic formula. If we expand the equation, well get this:
Our next step is to split this equation into workable parts. First Ill move out the terms without the h multiplier:
Now Im going to split the second summation depending on whether they are multiplied by h or h2. At the same time, Im going to move the multipliers to the outside of the summations since they stay constant.
At this point, things are starting to shape up and we have the variables that we can plug into the quadratic formula! All three of them can be calculated using a simple for loop.
Once youve calculated the value for h, you can go ahead and offset those vertices.
Collisions (Incomplete)
Two blobs, A and B Calculate the center of mass for both blobs. Dont use the polygon centroid formula. That gets screwed up when the polygon self-intersects. Now that you have the centers, you have the option of doing an early exit if the distance between the centers is too large. This would probably be between 1.5 and 2x the sum of the radii of the two blobs.