Live data from Hacker News

Pathfinding

juhrjuhr.itch.io

11–20 of 48 posts

Re: Pathfinding

#11

One efficiency update you can make is that if background objects don’t move, then you don’t need to recalculate the path. So check if anything moved before recalculating.

Sure, but in games sometimes improving the average case is less important than the worst case.

Re: Pathfinding

#12

I remember fondly messing around with some pathfinding with some friends in my 20s and adding random amounts of cost to nearby nodes. This has the distinct effect of making NPCs meander around, or follow a "drunken path."

I like this idea. One could imagine certain types to skew the costs for interesting reasons. Small animals might want to move in a sort of scanning, zig-zag way for example.

Re: Pathfinding

#13
I'm surprised it takes several milliseconds to find a path.

We've been using A* to find paths in games for over 20 years now. We did it on CPUs with speeds measured in Mhz. Higher clocks and architecture improvements mean we're a couple orders of magnitude faster. How is it that it takes so long to operate on modern hardware?

Re: Pathfinding

#14
post #11

One efficiency update you can make is that if background objects don’t move, then you don’t need to recalculate the path. So check if anything moved before recalculating.

Sure, but in games sometimes improving the average case is less important than the worst case.

So you're saying everything always moves all the time so it's more efficient to just never check and have the algorithm assume something moved always.

Re: Pathfinding

#15
post #9

Neat article! This will depend on the type of game or application, but one thing I've been doing is to do the more rigorous pathfinding when the environment (collision map) changes in order to generate a sort of precomputed pathfinding map (grid, or graph). When I search a path, or route for an entity, then it's on that pathfinding map. Again, it depends on how that simulation fundamentally works. Some have natural P…

What you refer to is commonly called a navigation mesh: https://en.wikipedia.org/wiki/Navigation_mesh

Re: Pathfinding

#16
post #11

Earlier quoted context omitted.

Sure, but in games sometimes improving the average case is less important than the worst case.

So you're saying everything always moves all the time so it's more efficient to just never check and have the algorithm assume something moved always.

For most real time systems, including many games, it doesn't matter if one is more efficient than another because what matters is the predictability that comes from always rendering a complete frame in 1/60th of a second.

In many cases checking if absolutely nothing changed in a system isn't trivial either. You either have very fine grained tracking which involves a great deal of complexity and increased memory cost, or very broad tracking which results in a lot of false positives.

Re: Pathfinding

#17

I'm surprised it takes several milliseconds to find a path. We've been using A* to find paths in games for over 20 years now. We did it on CPUs with speeds measured in Mhz. Higher clocks and architecture improvements mean we're a couple orders of magnitude faster. How is it that it takes so long to operate on modern hardware?

I'm guessing it might be multiple paths for multiple NPCs. But not sure.

And if you were performance conscious, you certainly would not do lots of pathfinding from scratch on every frame.

Re: Pathfinding

#18
post #12

I remember fondly messing around with some pathfinding with some friends in my 20s and adding random amounts of cost to nearby nodes. This has the distinct effect of making NPCs meander around, or follow a "drunken path."

I like this idea. One could imagine certain types to skew the costs for interesting reasons. Small animals might want to move in a sort of scanning, zig-zag way for example.

Yes! Very creative thought. I hadn't tried abstracting the idea to other types of "effort."

Re: Pathfinding

#19
"This kind of efficiency problem is something that looks ripe for multi-threading, but the main problem I had here is that all the world state of the game is held on the main thread and in complicated structures"

Crazy idea but I wonder if it would be worth it to have the pathfinding thread simply have its entire own copy of the mutable world state. Then when anything changes the world, both copies are updated roughly in parallel.

It would be a ton of duplicate work, but if you're on a machine with cores sitting there doing nothing... why not?

Re: Pathfinding

#20

I'm surprised it takes several milliseconds to find a path. We've been using A* to find paths in games for over 20 years now. We did it on CPUs with speeds measured in Mhz. Higher clocks and architecture improvements mean we're a couple orders of magnitude faster. How is it that it takes so long to operate on modern hardware?

Games typically precomputed much of the pathfinding information and assumed a non-destructible world. The whole thing in the article about recomputing the blocked/non-blocked state is a thing many games with pathfinding simply didn't do at runtime at all.

They usually pathfinding on a larger granularity with more of the world aligned to a larger grid. Since asteroids are so organically shaped and freely movable in this case, it necessitates a finer pathfinding grid. It looks like they're roughly 6-8 pixels here. In an older game, it could easily be 16 or more. Pathfinding cost scales quadratically as the grid gets finer.

Also, while CPU speeds have increased, RAM access rates have not kept up. It's quite hard to actually keep the CPU busy and not have it stalled waiting for memory very often. "Data-oriented design" is a whole little subfield dedicated to dealing with this problem.

Post reply on HN