Jelly Mesh Deformation

Stuff I did.

Jelly Mesh Deformation

I actually thought Unity would offer a solution for soft bodies/jellies, but I was wrong about that – clearly, there are 1001 Assets for that on the Asset Store but I am not really the kind of person who just will buy-in on an easy solution – so there I went off and made my own.

Tech Demo:
You can find a tech demo on itch.io in which you can set the values yourself and play around with it a bit.  You also have the option to switch between the standard Unity sphere and a procedurally generated sphere to see the impact of the vertice count.

How it works:
The JellyPhysics script does cache the mesh of the game object it is attached to. I am then using a loop to add all the vertices into an array of the original vertices and an array of displaced vertices.
We also need an array for the vertex velocity, since we are adding velocity to certain vertices while deforming the mesh. In this example, I am using two forms of input – for once I am using the OnCollisionStay function, which will detect any collision of the mesh with another collider. Here, this is the ground. I am also using the MouseInput.cs, which can be found in the GitHub repository as well. I’ve also made my own gravity – this is optional to be turned on and off with a bool in the inspector. For this to work you need to attach the Gravity.cs to the game object that is supposed to be the ground. You’ll also have to tag this game object as “Ground”!

Code Source:
You can check out the source code for my jelly on GitHub.

687474703a2f2f692e696d6775722e636f6d2f6579317863594d2e706e67

Tech Demo Gif – 

Leave a Reply

Your email address will not be published. Required fields are marked *