kandi X-RAY | astar Summary
kandi X-RAY | astar Summary
DEPRICATED
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 astar
astar Key Features
astar Examples and Code Snippets
Community Discussions
Trending Discussions on astar
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
I'm trying to do something a little bit different then the usual.
I have a 3D gridmap node setup and I'm trying to autogenerate the dots and connections using A* Instead of creating obstacles tiles, I'm creating walls in between the tiles, so the tiles are still walkable, you just cannot pass through a wall . I figure it that out all already
but I have no idea how to code how to connect the points in a easy way and not connect points that has walls in between...
I'm using a RaycastCast Node to detect the wall, and his position as it walk through every gridtile
but I can't figure it out a nested loop to find the neighbors points to connect
this is what I tried to do (obviously get_closest_point() is not working the way I wanted). If I could get a point using only Vector3 Coordinates, I think I could make it work.
EXTRA: if you guys can show me a way to clean the code, especially on the "FORs" syntaxes, because I kind don't know what I'm doing
Any other clean code recommendations would be amazing and very much welcomed
At the end has a visual draw(image) of the logic of the idea.
...ANSWER
Answered 2021-May-18 at 20:49Let us establish a mapping between coordinates and point ids. Given that we have a floor_size
, this is easy:
QUESTION
I have the following basic code
...ANSWER
Answered 2021-Apr-08 at 03:40Solved by adding the following to CMakeLists.txt
(thanks @alterigel)
QUESTION
Rust's Petgraph library has a bunch of filter 'adaptors', but I haven't been able to find any examples or tutorials for how to use them. Some (but not all) have constructors, such as EdgeFiltered.from_fn() which takes a graph and a function, but it's not clear how you'd then use it with the search methods like Dfs or astar as they don't have filter parameters.
So how do you use these filters? For example, if I had a graph with integer edge weights how would you:
- Perform a depth first search but excluding edges with a negative weight,
- Perform an astar search excluding edges with a negative weight?
ANSWER
Answered 2021-Mar-17 at 16:15The adapters implement GraphBase
, you can just wrap your graph in them and pass the adapter struct to e.g. Dfs
:
QUESTION
I am using Python's Queue.PriorityQueue
(in an implementation of the A* algorithm, though I'm not sure if this is relevant). I'm using it to hold objects that are non-comparable (an object class provided by a professor that I cannot modify), and Python throws an error when it tries to add an priority-object tuple (ex. pq.put(1, object)
) when it's already holding a tuple with the same priority.
This is the relevant part of the error:
...ANSWER
Answered 2021-Mar-03 at 00:23Ok, just in case someone ends up here, I ended up taking superb rain's comment into consideration since I was looking for a simpler solution, and I didn't really have time to overhaul my solution to make it more efficient or better. I just needed something to work.
The solution was basically just implement the suggestion here. If there's anyone that's looking at this that just really doesn't understand how Python works (like me!), stick this at the top.
QUESTION
I'm creating a MEX to find a path between two nodes using the A* algorithm. The code works as expected, retrieves the right result and everything seems to be fine, but when I return from the method that calls the MEX, Matlab simply shuts itself down.
As I know sometimes Matlab creates a pointer to the same memory address when the user tries to create a copy of a variable (I.E. A = 3; B = A, then A and B are pointing to the same memory address, even though Matlab shows them as 2 independent variables) I used an old trick that consists on performing an operation directly to the copy of the variable, even if its a silly one, Matlab will think that the two variables are no longer the same and will create a copy of it (I.E. A = 3; B = A; B = B+0, now A and B are stored as different and independent variables).
So the only way that I have found to fix the issue is to do what is shown below in function getWP:
...ANSWER
Answered 2021-Feb-18 at 08:321) If nothing is altering the content of the first parameter, why should it crash when returning from getWP?
[Node.cpp] 'double* tempVal' was not allocated, although the code worked, this was possibly messing with the integrity of prhs[0] thus causing Matlab to crash when returning from the function that invoked the MEX.
The solution was to declare tempVal as 'double tempVal[1]'. After that, the testAStarC.m the line 'cellNodes{keyID}.x = cellNodes{keyID}.x;' can be removed without causing the error.
Although unrelated to the crash, the use of memcpy to get scalar doubles has been replaced with mxGetScalar().
Node constructor:
QUESTION
I'm trying to look into the A* Algorithm but I'm kind of having a hard time understanding a specific part. So the A* Algorithm Python Code with the example is this:
...ANSWER
Answered 2020-Nov-26 at 09:33I think the clue is that you have to take into account the two lines above this for loop as well:
QUESTION
I'm making a game in Unity where 'enemies' spawn in (controlled from a script on a player), I'm using prefabs of the enemies, I have got the enemies to spawn in but the pathfinding isn't working. I know why - it's that when you reference the player transform while the enemy is in the scene there's a link but once the enemy is a prefab it can't access the player's components as it's not in the scene. I did a bit of researching and found the answer - I needed to instantiate the enemies like normal, but set this to a variable, enemyGO
for example, and then access the enemy's AIDestinationSetter
script through enemyGO.GetComponent().target = gameObject
- this would assign the target
value of the pathfinding target to the player (gameObject
). This would all work well, but it kept saying that it could no find the AIDestinationSetter component. This, after a while of tinkering, proved to be (I think) because in the script, the AIDestinationSetter
is within a namespace.
Here's the AIDestinationSetter
code:
ANSWER
Answered 2020-Nov-25 at 19:56You probably rather ment
QUESTION
I encountered some runtime errors when I was trying to finish a A* algorithm for tsp problem. The program doesn't want to reach the main function. Here is my code, it is long.
...ANSWER
Answered 2020-Nov-24 at 17:51You call back()
on an empty vector. But please use a (good) debugger before posting here! GDB is good but no really easy to use...
QUESTION
The algorithm searches straight upwards and when it reaches the barrier, it just stops, instead of going to the right Here. I am new to graph-algorithms and have just learned about them, so I am clueless when it comes to implementing them.
My code is not optimized, however, I will optimize it later. Here is my code:
...ANSWER
Answered 2020-Nov-04 at 15:50I commented out your open_set_hash.remove(current)
. I don't see why you remove the current from the visited list? Also moved the came_from[n] = current
inside the if condition. This was to get the reconstruct_path
function to work properly.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install astar
Rust is installed and managed by the rustup tool. Rust has a 6-week rapid release process and supports a great number of platforms, so there are many builds of Rust available at any time. Please refer rust-lang.org for more information.
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