← everything

PrimortalGame DevelopmentPathfinding

Adding/deleting entities & path-finding improvements

Up until today, entities could only be added to the world when the Tiled map was loaded. But I’ve added dynamic system events for registering and deleting entities. In this demo video, I added a button to spawn a new entity, who will try to walk across the map before triggering their own deletion.

I’ve also improved my NPC path-finding algorithm immensely.

There are still two improvements I want to make before moving to my next focus:

  1. Predict future (non-)impediments: if an entity that is in an NPCs way is actively moving (out of their way), we should ignore their impedance. As of right now, all NPCs think all other (moving) NPCs are just static obstacles. They all try to walk around each other, even though they’re all going to the same place. It’s more like a stampede than a queue.
  2. Backtracking when stuck: If two NPCs get in each other’s ways such that there’s no way to get around each other - they’ll just get stuck forever. I want to add a mechanism to walk backwards a few tiles on a random rare occasion, letting the other NPC through. This would be more of a failsafe than a feature - to prevent a game sequence from getting permanently stuck.

I can’t believe it’s been over 10 years since I first learned of A* in school… It was honestly one of the most magical home work assignments I did - just a few dozen lines of code and, ✨ta-da✨, magic, you’ve got something “intelligently” moving around your world…