Essentially I am using physics to provide intuitive procedural animation. I have a gelatinous object which moves, rotates, has a Rigidbody2D component, and allows smaller objects with their own rigidbody2ds to enter it. I believe the best way to achieve this collision is with 2d joints like SpringJoint2D, but if you know of a better / cleaner / more performant way, I would like to try it.
This is my first game, and I’m pretty clueless when it comes to Unity / C# performance
My thought was to create the 2d joints I’ll need to pull and rest the objects (while still allowing them to jiggle a little) using OnCollisionEnter2D and gameObject.AddComponent(). If performance dictates I keep the joints already made and disable them when not in use, that’s cool, but it could mean there are 30 joint components on the same object which will always be on screen. Otherwise, I can delete the components as soon as I am done using them and recreate them when they are needed again.
The gelatin moves, rotates, and pushes things bigger than itself, and if it collides with something smaller than itself the smaller objects are pulled into it and then rest like fruit inside a jello mold. There may be any number of smaller objects colliding with the gelatin at any given time, each with different sizes, masses, and drags.
I tried to find a package on the Unity asset store which would provide this behavior, but couldn’t. I need to keep the rigidbody2d components on all objects so that objects within the gelatin can push each other.
Thank you for your time!