I am using the Pro Version with Follower Entity Movement with Local Avoidance on a Grid Graph for building a RTS and the package is awesome. When I am marking my buildings as grid obstacles everything works great. Units dont get pushed into buildings and desired wall distance is a great addition. However when buildings are destructible I am using tags with high penalties instead of obstacles so that units can decide to attack them. I am using raycasts to check when a unit is trying to pass through a building and then I stop the pathfinding and switch to attacking. After that I delete the penalty and then unit continues.
The problem I am having is that when a unit does not decide to go through a penalty zone it can still be pushed into it by local avoidance or other things because a penalty zone is not a real obstacle. Basically I want the buildings to still be an obstacles for the pathfinding so it supports local avoidance and desired wall distance but a unit can also decide to attack it when its makes sense instead of going around it.
The only solution I can currently think of is making 2 grids / layered grid. The first one is for the actual movement with obstacles for buildings. The units would also be on that one. The second one would only be for the path calculation and then I would copy the path vectors from that grid to the first one. But this solutions seems to overcomplicated and I dont have any experience with manual pathsetting. It would be great to know how I could solve this problem or if I should use a totally different approach and what the general solution for destructible enviroments is.
Other People also had this problem, but aaron answer was always to read the tag documentation, which does not solve my problem sadly.
Hey thanks for making a new thread for this, highly appreciated!
Basically I want the buildings to still be an obstacles for the pathfinding so it supports local avoidance and desired wall distance but a unit can also decide to attack it when its makes sense instead of going around it.
Perhaps the better way of going about this is to use a DynamicGridObstacle for the buildings. Or at least form what I’m reading I believe that’s the option you want? And to make it stay the desired distance from the wall, you could use modifiers on the agent (namely the Radius modifier)?
For the debris, you could just make that a standard object without making it any kind of Astar obstacle and do your raycast logic as you have already. But you want them to also go around if it makes sense, and also sometimes just attack the debris, right? In that case you’d probably want to take the nodes of the graph with debris over them and give them a penalty. Here’s an excerpt from the documentation about penaltys:
You can change the penalty on the nodes. This is used to make some nodes harder/slower to traverse compared to other nodes so that an agent will prefer some paths before others. There are some limitations though. You cannot specify negative penalties since the algorithms used cannot handle that (and if they could, the system would be a lot slower). However, a common trick is to set a very large initial penalty (which can be done in the graph settings) and then decrease the penalty from that high value. Note, however, that this will make pathfinding slower overall since it has to search more nodes. The penalty values that are required are quite high. There is no real “penalty unit”; however, a penalty of 1000 corresponds roughly to one world unit of travel.
Thanks for your reply, I dont think you totally understand what I am trying to achieve. I had a working system which is using dynamic grid obstacles for buildings, which I can place, and everything works great. However I cannot think of a way, where units consider attacking the building and not going around it without using tags. So I decided to remove the dynamic grid obstacles from the building and swapped them for GraphUpdateScene Components with penalty tags. Now if they way around is too long it decides to go through the building and I detect that. Then I stop the pathfinding and let the unit attack the building, destroy it and remove the penalty. This works great however the problem is that now the building is not a “true” grid obstacle anymore but just a penalty zone which messes up obstacle avoidance, because now units can get pushed into the building.
Basically I want the building to be considered a dynamic grid obstacle for the collision part of the pathfinding and a penalty zone for the path calculation.
I think I was under the impression of “buildings are around the environement, and can be destroyed, but the destroyed buildings now block the path”, but it looks like it’s more like “non-destroyed buildings will be in the pathway of units, and I want them to try attacking the building instead of going around in some cases”. Is that correct?
I just want to make sure I got this right before I continue. Pics/vids help a lot here! I’m trying to match my mental image of this to yours.
Yes, now we are on the same page. Here is some footage showing the problem:
This clip is using the dynamic grid obstacle and everything works flawless. Distance to wall is nice and no glitching in the wall. Dynamic Grid Obstacle Video
The second clip is using a penalty zone for the obstacle. I already made the zone quite a big bigger than the object really is. But things still get pushed into it, because it does not provide real collision.
They just don’t care about the obstacle since it’s not an “obstacle”. So you’re looking for a way to make them treat it like a physical object without it setting walkability to false, which would just make the units pathfind away from it altogether. Or at least, I hope I’m finally getting the issue…if not please feel free to correct me!
But if that’s what the issue is, then I’m honestly not sure what solution is available here. I’m not finding anything that makes it a physical barrier than can be interacted with. Specifically needing an object that has the physicality of an obstacle (for units not wanting to be bothered) and the split decisiveness of tagging (for units willing to go through the hassle) is rough. That said, I want to point out a few thoughts that may help. I’ll also let @aron_granberg know about this one, he may have some better ideas.
What I’d recommend is looking into the example Recast graph where there are Interactable chests, as well as OffMeshLinks - A* Pathfinding Project. I don’t think either are a drop-in solution but I do believe there is some possible solution here using tagging and maybe a custom interaction script (of which you seem to already have, so it could probably just be modified). Again, I’ll see what ideas Aron has for this use-case.
Thank you very much! I already looked into recast graphs but my whole game is based on a grid system and it would not make much sense to switch in my opinion. I will experiment further and hope that maybe aron has a solution or I find my own.
Understandable. I’ll keep my eyes out for things in the documentation that may help/apply here regardless, and if I think of something I’ll post about it here! If you come up with a solution I’d love to see if posted here as well so I can see