I have computers in too many different locations. It’s a good and also an annoying problem to have. I get all excited and giddy to work on my code, and then I boot up a computer I haven’t used in a while, see how many app and software updates are needed, and spend valuable would-be coding time on system maintenance.
/endrant
Today I set out to correctly prevent player spheres from travelling too far away from the hands. My issue last time was that I over-engineered a solution and it ended up creating so many new bugs that I didn’t even bother committing the code. This time, I wanted my solution to be purely physics-based so that existing forces on the sphere aren’t being interfered with by directly-set transform positions.
I took some time to build context with Claude before getting started. It suggested applying a strong opposing force when the sphere exits its allowed boundary, similar to how a spring works.
Unfortunately, the gravitational forces a player exerts on other players stay active even when both of a player’s hands are closed. Therefore, bouncing a sphere back into play has the potential to create inaccurate SDF shapes and particle behavior, as well as confusing locations for the players.
Therefore, I instead suggested adding drag to halt the sphere as it moves away from the boundary. This approach worked much more cleanly.
As you can see, I drew gizmos for the metaball grid boundary (green) and the sphere boundary (orange), which helped me calibrate proper scale and drag settings for the sphere boundary. I also modified my DummySceneControl component to make the hand sprites go semi-transparent during hand-closed states instead of disappearing completely.
I wanted to get rid of the horizontal movement that occurs when the spheres experience drag. To do this, I updated the boundary force so that drag is equally applied to all velocity components, not just the velocity component perpendicular to the force boundary.
The last step was adding my new boundary force settings to the in-game settings menu, which I accomplished in a single prompt or two. I’m pretty satisfied with this behavior now! Next, I’d like to make it so that sphere positions reset completely if the hands remain closed for X duration when a player’s sphere is stopped outside the boundary.