Hi ! Just got the package and was running thru the documentation.
I am looking for advice as to which combination of movement scripts + pathfinding + graph generation types I should understand more to suit my project.
My project (using Unity 6) is a top down 2d grid made up of cells.
Player clicks on any of the cells and the player will, using A*star, move to that cell. Movement is cell to cell, can allow for diagonal movement and there can be obstacles in any of the cells
I think the HexagonalTurnBased example seems to be most suitable but any advice and pointers will be greatly appreciated!
Thanks
p.s. example 3D scenes are not working OOB with Unity 6
quick update, i used Point graph and got it to work. 2 questions:
how can i make the player(green) to move from cell to cell instead of a curve
do i need to do a AstarPath.active.Scan() every time i trigger a move? i was seeing some of the examples where objects appear dynamically and the moving object react immediately so probably i missed something there
Ahh, I was looking into this earlier, but I wasn’t able to respond in time- glad you found the Point Graph, that’s what I was going to suggest haha
For your first question, what movement script are you using? AIPath? Custom solution etc? I can take a look into this.
For the second question, as far as I know, no you should only have to do a scan if something changes in the graph- you’re calling it every time you scan? If so, let me know what for and I can look into that too. (But generally no, you don’t need to Scan every time)
I was using the example where I create path and then use a coroutine to run the path. I tried again using Ailerp and that seems to be better.
I will try again come Monday. 1 quick question… when there’s obstacle it will move from cell to cell (orthogonally). With no obstacle it will move diagonally. I was wondering if it’s point system, wouldn’t the path be generated from 1 cell to another (I think I set it up so each cell is a node) orthogonally? Or maybe I’m doing something wrong …
If I’m understanding the question correctly (which I’m not sure if I am, feel free to elaborate ), would pathfinding to simply the next orthogonal node be what you’re trying to do? Or are you saying you want to restrict movement either diagonally or orthogonally based on if there’s an obstacle?
restrict movement either diagonally/orthogonally to the next node
here’s a Gif of what i have done so far. so i changed the max period to 1 and it seems to have a strange reaction when there’s no obstacle (that little jerk in pathing).
hopefully the gif shows some of the issues i’m facing clearer
1-2-3
4-5-6
for the 1st case where no obstacle and player moves from 6 to 1, it can move 6->2->1 or 6->5->1
when there’s an obstacle(it only has a boxcollider2d on it) before move starts, its moving as desired.
if an obstacle appears after the move starts, you can see the small jerk happen
update: i switched to grid graph and its resolves the 1st case (moving 6 to 1 it will go 6->2->1)
still when obstacle appears it doesnt seem to “dodge” it immediately nor does it move diagonally in the last move to reach the final cell
i am also calling AstarPath.active.Scan everytime i trigger an entity to move. is that required? (i am assuming i need to do this if the grid changes like a new obstacle appears)
You can enable the Grid Graph’s “cut corners” setting to allow this.
Not every time you move the agent, no. But every time you change the graph. Alternatively, you can make smaller graph updates (see docs), but your graph is so small that this doesn’t really have any positive benefits.
What it the desired result for you? The agent was on its way to a now unwalkable tile. So when it recalculates the path it will discover that it is way off and quickly move to the valid path.
well the prototyping is small to test things out… the grid possibly will become quite big. When you mentioned smaller graph updates, does that mean i should split the grid up into smaller grids and each have their own graphs? sort of like rooms/regions?
when you say changing the graph, what happens if there are several entities moving around using AStar. Will their pathing cause them to collide with each other or will AStar be able to allow them to avoid each other as they move along the path?
so desired result is that as its walking to the destination, if an obstacle appears in the path, it will divert. Similar to your video where the player is walking and then some rumble fell in front of them and they pause or move around it
update:
so i refactored to use AIDestinationSetter to set target but also trigger AstarPath.active.Scan() when the obstacle appears/disappears. This allows the player pathing to adjust accordingly. But is this the correct way to implement? I am thinking to call a Scan() regularly can be quite expensive? Also what happens if there are 2 moving objects and they cross paths, what happens then?
Pathfinding in itself does not account for other agents. Local avoidance is included in the package for this purpose. But looking at your gifs, I doubt that local avoidance will give you the feel that you want.
If you have a turn-based game, you can take a look at Utilities for turn-based games - A* Pathfinding Project
It looks like it does, in your video.
If you want a better response time for your agent, then you can call ai.SearchPath immediately after scanning the graph.
1 last question… how can I configure the pathing to ignore an entity’s own collider? Given that all my entities will have their own collider so pathing they can avoid others but it seems having its own collider may cause a “hit” in the pathing?