Blog

Shoves Per Second

Posted

The shoving simulator is coming along, and in the process I learned an important lesson about physics body name collisions that made me think I was completely failing to grasp how colliders worked. After a couple pulled hairs, it turns out the all-too-simple solution was to use groups for limiting collider effects rather than keying on object names.

Multiple layers and masks might seem even easier at first, but the engine’s collision detection needs to handle a lot of things that can’t be shoved (walls and pillars, for example). The masking approach breaks down unless every NPC gets two collision objects; one for basic game world physics and another for interactions with other NPCs. Which is doable, placing each in different layers, but is more unnecessary work than just taking advantage of groups.

For every action, there is an equal and opposite reaction.

Just as importantly as shoving starting to work, so is the recoil and recovering. Bringing a little bit of added chaos to crowded situations, one NPC shoving another doesn’t just push the latter out of the former’s way. The shover and shoved both gain some distance from each other out of the initial interaction, and have the chance of colliding into others around them. This can (and does in debugging runs) lead to chain reactions of a room full of ping-ponging NPCs. Because I’m not yet placing any limits on new NPC spawning, letting it run for a couple minutes nearly guarantees a scene full of physics bodies bouncing off each other hundreds of times per second, only slowing down when a bunch of unlucky ones get knocked off the limited floorspace into the empty void below.

With this basic mechanic functioning, the next steps (I think) will be more robust destination selection for NPCs. Right now the prototyping scene just has a handful of targets and each NPC is randomly selecting one of them to walk toward and stand on. I may also consider starting to work on a way for NPCs to exit the scene that doesn’t involve them falling to their deaths. At least not all the time.

Reading List

Entries are not endorsements of every statement made by writers at those sites, just a suggestion that there may be something interesting, informative, humorous, thought-provoking, and/or challenging.