50
votes
Efficiently pathfinding many flocking enemies around obstacles
This sounds like a use case for Flow Fields.
In this technique, you do a single pathfinding query outward from your player object(s), marking each cell you encounter with the cell you reached it from....
28
votes
How can I shorten the length of time spent on finding a path using my A* pathfinding code?
Let's start with some general C# optimization advice:
Avoid heap allocations in your hot path. That means anywhere you have new Foo(...) where ...
27
votes
Accepted
Is A* efficient even when the obstacles are moving?
There are multiple algorithms that are much faster than A* when you need to recalculate a path with moving obstacles. See here under "Simple Recalculations".
However, you're not likely going to find ...
22
votes
Accepted
Pathfinding with lock and key?
Standard pathfinding is Good Enough -- your states are your current location + your current inventory. "moving" is either changing rooms or changing inventory. Not covered in this answer, but not too ...
18
votes
Accepted
How to reduce the time taken to path-find to an unreachable location?
Using a bidirectional path finder usually solves this issue if the area the player is stuck in is small. They basically advance from the player's position and the destination at the same time and when ...
15
votes
Maintaining unit formation while following path
My approach would be:
Designate one soldier of the formation "the leader". (this does not necessarily need to be the actual commanding officer of the formation. You can pick any soldier. ...
14
votes
Is it possible to use nav-mesh in 2d game in Unity?
In case anyone Googles this later, you CAN use nav meshes in Unity. I'm using unity 2018.2 and set up a navmesh in a purely 2D top down tilemap game I'm working on.
Check this thread in the Unity ...
13
votes
Pathfinding with lock and key?
Backwards A* will do the trick
As discussed in this answer to a question about forward vs backward pathfinding, pathfinding backwards is a relatively simple solution to this problem. This works very ...
13
votes
How to reduce the time taken to path-find to an unreachable location?
You should make a sort of connectivity map - by flood-filling all unconnected walkable areas and marking each one with a different tag, once at game start (and every time when terrain changes). Then, ...
13
votes
A* Algorithm for Tactical RPGs?
When you want all possible movement options of a unit, use Dijkstra's Algorithm.
The difference between A* and Dijkstra is that Dijkstra gives you all the possible shortest routes achievable with a ...
12
votes
Determine route between rooms
You have a common misconception. A* isn't made for grids, it usually uses graphs. A grid is just a specialized graph with each node having 4 edges (apart from the edges and corners).
12
votes
Accepted
How to adapt pathfinding algorithms to restricted movement?
Welcome to the wonderful world of non-holonomic motion planning. I recommend doing this using a lattice grid path planner. Other alternatives include the kinodynamic RRT, and trajectory optimization. ...
10
votes
Is A* efficient even when the obstacles are moving?
Yes. A* is still the way to go in almost every case. It's your node cost calculation that becomes dynamic and therefore more complex to calculate and track.
If you already know where the moving ...
9
votes
How does HPA*(Hierarchical Pathfinding A*) really work?
One of the creators of HAA* (a generalization of HPA*) wrote a very accessible article explaining how it works on aigamedev.com. Unfortunately that site seems to be dead, but fortunately archive.org ...
8
votes
Accepted
A* Pathfinding Finding One of Many Goals
There are just two changes you need to make to your A* implementation to handle pathfinding to multiple goals / multiple destinations:
When expanding a node, instead of evaluating ...
8
votes
How to generate a random path on a 2d Grid
One common way to solve this type of problem is to still use a shortest path algorithm like A* that takes into account traversal costs. We just lie to it about what's "shortest" ;)
Here we assign our ...
8
votes
Efficiently pathfinding many flocking enemies around obstacles
A* is not performance heavy. I would approach this situation by varying the algorithms. Do A* from time to time and in between check whether the next step is free to step onto or you need evasion.
...
7
votes
Accepted
RTS pathfinding
With RTS pathfinding, your requirements are:
You have to compute paths for all selected units fast.
The pathfinding must take into account that a path may not be found (blocked)
The pathfinding must ...
7
votes
Accepted
How would I actually implement A* pathfinding in a 3D world?
What A* needs to work is the following:
Given the current node, get the list of possible nodes it can move to, with their costs.
The ability to evaluate the heuristic function.
Please notice I've ...
6
votes
Pathfinding with lock and key?
Edit: This is written from the point of view of an AI that is out to explore and discover a goal, and does not know the location of keys, locks, or destinations ahead of time.
First, assume that the ...
6
votes
Accepted
How can I maneuver an AI pirate ship for a sea battle?
I think we can actually plan a complete curve that meets your needs, using some techniques similar to my earlier answer about spaceship waypoints.
I'm going to assume that we can model your ships' ...
6
votes
Grid-based pathfinding for a lot of agents: how to implement "Tight-Following"?
If a entity has a successful reservation then you can mark its current square as available for reservation. Then check any entities that had a failed reservation.
If no entity can confirm their ...
5
votes
Accepted
How do you handle pathfinding for non-tilemap 2d games?
There is nothing about A* that is specific to a tile map or grid. A* is usable in any kind of directed graph so long as there is a usable heuristic - e.g., distance to destination. When there isn't a ...
5
votes
Accepted
Why is my A* algorithm is not taking future obstacles into consideration?
It looks to me like the problem is just a typo here in your node type:
public int fCost {
get {
return gCost = hCost;
}
}
This should be a <...
5
votes
How does heavily constrained delaunay triangulation work?
You're almost there. Once you have a delaunay triangulation of all the points (including constraint points) then:
foreach constraint edge:
Find all existing intersecting edges in the triangulation
'...
4
votes
How to force a sub-optimal path
You can do this by forcing your A* heuristic to be inadmissible.
An admissible heuristic is any heuristic which is strictly less than the true shortest path length. An example of an admissible ...
4
votes
How to adapt pathfinding algorithms to restricted movement?
Most path finding algorithms work on a arbitrary graph without restriction of geometry.
So what you need to do is add orientation of the car to each explored node and restrict which nodes are ...
4
votes
Accepted
What is a good path-finding algorithm when a target is moving?
You can switch between pursuit behaviour and A* depending on case. If chaser can actually 'see' the target (without obstacles on the way), it uses pursuit (maybe its characteristics makes it evade ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
path-finding × 739algorithm × 144
ai × 135
unity × 117
c# × 73
navmesh × 66
2d × 64
java × 41
grid × 36
movement × 30
optimization × 30
c++ × 28
tiles × 25
tilemap × 24
xna × 22
3d × 22
rts × 22
collision-detection × 20
mathematics × 18
javascript × 18
steering-behaviors × 17
graph × 17
collision-avoidance × 15
procedural-generation × 14
physics × 12