site banner

Tinker Tuesday for November 26, 2024

This thread is for anyone working on personal projects to share their progress, and hold themselves somewhat accountable to a group of peers.

Post your project, your progress from last week, and what you hope to accomplish this week.

If you want to be pinged with a reminder asking about your project, let me know, and I'll harass you each week until you cancel the service

2
Jump in the discussion.

No email address required.

Well, as usual getting something animated to work turned out to be a massive pain in the ass, so I'm calling it quits for today and leave you guys with a screenshot.

What's happening here is that all these little dudes are following the mouse cursor (marked with the red dot, because it's not captured by the screenshot). When they run into each other they push each other out of the collision area, and mostly keep trying to walk towards their target, a sort of "zombie horde trying to eat your brains" mechanic. The colors show with how many other entities each one has collided. Blue means no collisions, touching a single other unit turns it red, and then the more collisions happen they gradually turn yellow.

In my first approach to this project I ran into the issue of collision causing the horde to get "fuzzy" (kinda like this). The collision resolution only caused units to run into each other more, which needed more resolutions in the following frame. Particularly the center of the horde was under a lot of "pressure" causing some freaky Brownian motion.

I managed to solved it this time around. First, the original approach was over-complicated - I was calculating some weird "reaction force" to a collision, trying to force a pusback effect. I decided to drop it altogether and only leave the "resolution" part where units are moved away from each-others collision areas.

This still generated a lot of fuzziness, because each unit still tried moving toward the target on each frame, so they kept putting pressure on each other. On a whim I decided to multiply the "follow the target" vector by the dot product between it, and the "collision resolution" vector. So if a unit ran into another, it would get pushed back, but if it got pushed on from behind, it would still be allowed to move forward. It turned out to be very good for stability, and removed most of the fuzziness.

This still left me a bit unsatisfied because it made the horde behave too "sticky". If you moved your cursor the units with a relatively direct path would come at you, while the ones coming at a sharper angle would run into each other and get stuck. It was hard to get a "you're getting swarmed" effect, because they were unable to approach the target from behind, once they started reaching it. I tried a few ideas with varying degrees of success, but what ended up working well was, in turn, adding the cross product of "collision resolution" vector and "follow the target" to "collision resolution", this allowed for a "make some room with your elbows" effect as the sideways movement got an extra push.

This was good for mobility, but again had impact on stability resulting in the return of fuziness. So as a final tweak I divided that "extra push" by the number of collision (with some magic factors attached, but you get the point - more collision less of a sideways boost). This finally resulted in a nice compromise between stability and mobility. You can see how the edges of the swarm tend to be blue, which means they can keep moving towards the target along the edges of the group.

If anyone wants to try it out, here's the github repo