Ignoring the intention I set at the end of yesterday’s log, I decided to continue iterating on the script I built yesterday with the help of ChatGPT. I felt like I was close to figuring it out, and I was right. With zero googling (OK, I looked up one basic vector math thing…) and zero GPT prompting, I got my spheres attracting properly. As with my original energy ball mechanism, I implemented a combined velocity and distance threshold for the spheres to stop moving completely at. I also implemented a relationship between the stop gravity distance and max distance between the objects, which helps bring the objects closer together over time. With that in place, my simulation looks like this:
I was tired of getting errors when using GetComponentsInChildren, so I updated my Unity version. Sure enough, that fixed the bug. Less variables to set in the inspector means less potential for error.
The next step was for me to implement scaling of the spheres as they merge. I used a Lerp function and actually got the effect I desired pretty quickly.
Unfortunately, that scale code was a lucky fluke (only 2 lines!!!) and didn’t work when the spheres were different sizes. I began to rewrite my scale algorithm using InverseLerp instead. That makes more sense, given that my input params are the distance to start scaling at and the distance from the midpoint between the objects. It doesn’t quite work yet.