Yesterday I got started on my attempt to make an Instagram demo showing off the metaballs. The idea for the post is pretty simple. Facing the camera, I open my left hand, then my right. When each hand opens, an energy ball appears around it. I gradually bring my hands together over my head, where the energy balls merge smoothly. Like I said, simple in concept—but way more difficult than expected in implementation.

Getting the metaballs to track to each hand was simple enough.

metaballsToSDF.SetMetaballPosition(
	playerConstructor.metaballIndex,
	playerConstructor.HandLeft.transform.position
);
metaballsToSDF.SetMetaballRadius(
	playerConstructor.metaballIndex,
	playerConstructor.sphere.transform.localScale.x / 2f
);
metaballsToSDF.SetMetaballPosition(
	playerConstructor.metaballIndex + 1,
	playerConstructor.HandRight.transform.position
);
metaballsToSDF.SetMetaballRadius(
	playerConstructor.metaballIndex + 1,
	playerConstructor.sphere.transform.localScale.x / 2f
);

But really, it was setting up the VFX graph where I ran into trouble. For starters, I only have one animator set up for controlling initialization of the particles and hand open/close animations. I’ve been meaning to redo the initialization anyways and my failed attempts yesterday pointed me to the root of my issues: sharing one VFX graph for both hands. My work earlier this week should have been clue enough to the advantage of keeping logic for particles from each hand independent, as I created separate VFX graphs to receive spawn events for each hand.

Instead of moving the energy ball VFX logic into those graphs, I’ll do the opposite by duplicating the energy ball VFX, assigning one to each hand, and moving the hand VFX animation graphs into those graphs. The reason for this is positional. Because of the way I generate the SDF for the metaballs and my need to keep that SDF in place, I think it’ll be easier to keep the VFX graphs stationary at (0, 0, 0) and install positional binding for any parts that need to follow transforms.


Making some good progress (finally).


Tags: gamedev unity vfx metaballs csharp sdf animation