pathfinding | Visual explanation of pathfinding algorithms
kandi X-RAY | pathfinding Summary
kandi X-RAY | pathfinding Summary
Link to hosted demo: Breadth-first search, Dijkstra and A* are three famous path-planning algorithms that run on graphs. They can all be seen as a specialised version of a graph search with two different parameters, the queue used and the heuristic used. The aim of this project is to explore and visualise how the different algorithms explore through the graph depending of the parameters chosen.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of pathfinding
pathfinding Key Features
pathfinding Examples and Code Snippets
Community Discussions
Trending Discussions on pathfinding
QUESTION
I'm working on a 2D game in Unity and am using the A* Pathfinding Package from Aron Granberg.
Everything appears to be working fine. AIPaths are being generated and AI Agents are navigating from point to point and avoiding obstacles as expected. It's fine except for one thing.
The position.z
of the AI Agent is incorrect.
The spawn origin of the AI Agent has a z of 0, and the target point has a z of 0, yet the AI Agent's z fluctuates between -9 and -1 as it traverses the path. The path itself appears to have a z position of 0 at each waypoint.
I haven't modified the code in the package at all and just followed the documentation when setting it up for 2D.
Any ideas what could be causing this?
NOTE: I haven't included a screenshot of it, but the prefab that is being spawned in as the AI Agent has a transform position of (0,0,0).
The A-star pathfinder object:
The AI Agent object (note that the Z pos is not 0):
The spawn point object that sets the spawn for the AI agent:
The destination target object that the AI Agent is heading to:
...ANSWER
Answered 2021-Jun-14 at 02:09In case anyone else runs into this problem.
The fix was to add a Rigidbody2D to my AI Agent and set the gravity scale to 0.
Even though my game doesn't use Unity's physics system for movement and the Astar package can move AI agents by transform, for some reason it requires a Rigidbody to keep the Z position at 0.
I'm still not really sure why this solves the problem because, when I was debugging the third-party Astar code, it always returned nextPosition values with a Z position of 0 yet the actual position that the AI Agent was updated to had varying Z positions...
If you have more info, leave a comment and I'll add it to the answer.
QUESTION
When I run my code it throws a segmentation fault and I have tried rewriting the code several times. Still to no avail, it won't even run. The segmentation fault happens as soon as my program is launched. What it's supposed to do is print a path on screen using the ncurses library in Linux, from the given coordinates. Here is the problematic snippet with the lines where gdb said the segmentation fault was, also it (snippet) reproduces the problem.
EDIT: This will help explain what I'm trying to do, but using dynamic arrays. Breadth First Search
EDIT 2: The variable frontier is supposed to keep track of the X and Y values at a specific index. The add_neighbors function is there to add all four neighbors (providing they aren't already added) to the frontier and came_from arrays.
frontier[index][0] is X value.
frontier[index][1] is Y value.
The before the first while loop I set the start position x1 and y1. During the first while loop, it increments getting the new coordinates from the frontier, then processing and adding to came_from array.
For example:
(x1,y1) (x1+1,y1)
(x1,y1+1) (x1+1,y1+1)
(x1,y2) (x2,y2)
I'm trying to get from (x1,y1) to (x2,y2). Sure hope that explains it better. What I'm trying to implement is a Breadth First Search (BFS) algorithm. Using two arrays, one is frontier (keeps track of visited positions) and came_from (keeps track of X and Y the path from x1,y1 to x2,y2). Updated the code to reflect the first answer. Plus added a comment to explain where the error might be, not really sure but I've been debugging it. It looks like the came_from array never gets set with x and y.
The Code:
...ANSWER
Answered 2021-May-23 at 17:26Some of the allocation sizes are incorrect:
frontier = malloc(sizeof(frontier) * MAXHEIGHT * MAXWIDTH);
should be
QUESTION
I am new to C#/Unity and looking for a way to slow down onDrawGizmos. Currently everything works great.
...ANSWER
Answered 2021-May-09 at 12:27Might not be the best solution, but you can use a counter to execute the code conditionally, like this:
QUESTION
In my code below, the value passed by the for loop is not in the list that is being iterated. I am coding a simple pathfinding function in which a start and an end point are passed, and the output is the pathway to get from the start point to the end point. The dictionary called connections has a key for all the points on the map, with the value being a list of all the other points it is connected to. You can only get from one point to another via the NODEs (think Nodes are like roads and the letters are houses).
In this case, I input a start point of 'A' and an end point of F. The expected output is:
...ANSWER
Answered 2021-May-07 at 00:34Barmar found it first but I'll spell it out (I missed his meaning first time through myself). Change this statement at the end of your function:
QUESTION
I am trying to make a maze/horror game. I used an online template in the Roblox library as my enemy. I used pathfinder as you will see in the code below. It's finding me like it's supposed to, except it only goes for my LAST position. As you can see in the image below, it completely skipped me, went to my LAST position, then started chasing me. I don't know why it only goes for my last position, and not my current position.
...ANSWER
Answered 2021-May-05 at 15:02Your NPC's pathfinding updates when you call path:ComputeAsync(rootPart.Position, characterPos)
. The reason it is not updating more frequently is that you are blocking the start of the next loop with the last line : humanoid.MoveToFinished:Wait()
Your code is telling the NPC that it must walk to every single point between every single player, which could take minutes at a time, before ever calculating the path again.
The way to fix this is to make it so that the path can be recalculated quickly and asynchronously. To do this, try something like this :
QUESTION
I have an array such as def list = ["pathfinding", " Gameplay", "Community"]
which I would like to iterate and eliminate the whitespace at the beginning of each element. So I though it would be easy using something like:
ANSWER
Answered 2021-Apr-27 at 18:24you can use String#trim()
QUESTION
There is a TLDR at the bottom. I have a python class as follows which is used to make nodes for D* Pathfinding (Pathfinding process not included):
...ANSWER
Answered 2021-Apr-23 at 02:25Once again TLDR included(Just so you can check if this will work for you).I found a workaround which preserves the time saving benefits of pickling but allows the nodes to be pickled even at larger sizes. Tests included to demonstrate this:
I changed the structure of each Node() in makenodes()
that is to be pickled by stripping it of it's neighbours so that there is less recursion. With the method mentioned in the question, a grid = np.zeros((40,50))
would require sys.setrecursionlimt(16000)
or so. With this approach, Python's in-built recursion limit of 1000 is never hit and the intended structure can be reconstructed upon loading the pickled file.
Essentially when pickling, the following procedure is followed.
- Make a list of all nodes with with their corresponding indexes so that:
QUESTION
I was doing a pathfinding visualizer in pygame and I pretty much finished but there's still one thing that I do not like about the algorithm part of it and it's the fact that when you press the visualize algorithm button it shows you the shortest path in yellow and all of the nodes the algorithm has visited ever in light blue but it shows you instantaneously and I want it to color the nodes accordingly step by step to actually reach the effect of visualizing (like in here https://clementmihailescu.github.io/Pathfinding-Visualizer/#), I tried to write some code in the function that seemed like it would have worked as intended but it didn't, here is the code:
...ANSWER
Answered 2021-Apr-14 at 10:42i think the problem is that you do not update the canvas in your while queue
loop.
the program will execute your bfs algorithm and then it will update the canvas.
i honestly don't use pygame very regularly, but i think to force the canvas to repaint you need to stick a pygame.display.update()
inside your while loop.
QUESTION
I'm trying to implement a pathfinding algorithm visualizer using a yield function on my algorithm that yields the list of visited nodes each time it visits one at the end of my function:
...ANSWER
Answered 2021-Apr-16 at 20:41You shouldn't have a while
loop inside your event loop or you main game loop. Use a flag instead to signal whether or not to update the algorithm:
QUESTION
function algorithm(){
if(startPoint === true && endPoint === true){
//add the heuristic distance to the start position from the final position
startPosition.h = distance([startPosition.x, startPosition.y]);
let openList = []
openList.push(startPosition)
let closedList = []
while (openList.length > 0){
//print(openList)
lowPos = 0;
for(let i = 0; i < openList.length; i++){
if(openList[i].f < openList[lowPos].f){
lowPos = i;
}
}
let currentPosition = openList[lowPos];
//currentPosition.check()
//if the currentPosition is the endPosition, retrace steps and find the path, then return this path
if(currentPosition === endPosition){
let curr = currentPosition;
let ret = [];
while(curr.parent != null){
curr.path()
ret.push(curr);
curr = curr.parent;
}
endPosition.end()
return ret.reverse();
}
openList.splice(lowPos, 1);
closedList.push(currentPosition);
let neighbours = neighbors(currentPosition);
for(let i = 0; i < neighbours.length; i++){
let neighbour = neighbours[i];
if(closedList.includes(neighbour) || neighbour.colour == "black"){
continue;
}
neighbour.check()
let gScore = currentPosition.g + 1;
let gScoreBest = false;
if(openList.includes(neighbour) == false){
gScoreBest = true;
neighbour.h = distance([neighbour.x, neighbour.y]);
openList.push(neighbour);
}
else if(gScore < neighbour.g){
gScoreBest = true;
}
if(gScoreBest == true){
neighbour.parent = currentPosition;
neighbour.g = gScore;
neighbour.f = neighbour.g + neighbour.h;
}
}
}
}
//meaning that either the path is not possible or the final node/initial node
has not yet been placed.
return [];
}
...ANSWER
Answered 2021-Apr-13 at 12:34It looks like you are not checking the diagonals. It is not a mistake. You are doing great.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install pathfinding
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page