So I’m using the dynamic obstacle script that came in the example scenes (Only have free version ) and I was wondering if there is a way to check when the graph has been updated. For example, I only want the npc’s to recalculate their route everytime the grid graph is updated. So I just need a check to see if it has been updated, and if it has, recalculate the route. If not I could just recalculate base on time, but this would be preferable. Any suggestions?
Hi
You would do it using GraphUpdateObjects. See http://arongranberg.com/astar/docs/tags.php (though you probably want to do it from scripting)
If one unit covers approximately one node in the graph, you can go with a cheaper approach. Basically:
GraphNode node = AstarPath.active.GetNearest ( transform.position ).node; if ( node != null ) { node.Tag = 13; }
Hm ok that looks like something I could manage. Thanks a ton, hopefully I wont be back asking more questions x)
Ah, yes, it was a static variable not an instance variable.
You should not try to use dynamic obstacles on the agents themselves, that will fail horribly (as you have seen). However what you can do if you have a low agent count is to associate a tag with each agent and update the graph under each agent to reflect what agent is standing on that node. So if agent 1 is standing on some node, that node will be updated to use tag 1. On the seeker you can then specify a tag mask for each agent so that they can only traverse the basic ground and their own tag (alternatively you can just add a huge penalty for the other tags, which is often preferable).
Also, you can try to use some kind of local avoidance system (not necessarily the one in the pro version). For example there is UnitySteer which is free, and I think there are a few others out there.
So with the tag thing, each agent would require it’s own tag, And then the node this agent is standing on would aquire it’s tag. Then every agent could only walk on nodes with their own tag? If I understand this correctly it makes sense. But how would I go about assigning nodes tags based on where an agent is standing?
I think what id like to do is implement some sort of temporary solution, and then hopefully get some money in a kickstarter so I can just buy the pro version.
And thanks for the help. I really appreciate that you offer active support to the community.
Ack forget it. I’m just rambling now but I tried what i had so far with ~10 enemies and i was getting about 20fps… I’m gonna have to scrap this idea and try to find a new way of getting the npc’s to avoid eachother. Can you suggest anything?? Maybe i’ll just have to dish out $100
Ok ok, I will not tempt you anymore… buuut regarding economy, you get 10% off if you purchase it with bitcoin
Thanks!
EDIT: This can be ignored. See below.
So I tried using the code you put above but I’m getting this error:
Static member 'AstarPath.OnGraphsUpdated' cannot be accessed with an instance reference, qualify it with a type name instead.
I’m not sure what this is really saying.
Also, I’m not entirely sure what is going on in this lines:
AstarPath.active.OnGraphsUpdated += OnGraphsUpdated;
AstarPath.active.OnGraphsUpdated -= OnGraphsUpdated;
What is OnGraphsUpdated?
And finally here is my code:
`
public void OnEnable () {
AstarPath.active.OnGraphsUpdated += OnGraphsUpdated;
}
public void OnDisable () {
if ( AstarPath.active != null ) {
AstarPath.active.OnGraphsUpdated -= OnGraphsUpdated;
}
}
public void OnGraphsUpdated ( AstarPath ap ) {
if (!isTarg && distance > 3)
{
seeker.StartPath(myTransform.position, whereToMove,
OnPathComplete);
}
}`
I’m no expert in programming, I’ve never had any formal training. (but I’m also no noob) Would you be able to briefly explain what’s going on here? Or what concepts I should further research?
Thanks in advance
EDIT: This can be ignored. See below.
Ok so now I got rid of the .active in AstarPath.active.OnGraphsUpdated and now it seems to be working like i’d want. Buuuuttt it seems as though I’m misusing this dynamic obstacle script. The issue is it’s attached to the object trying to find a path (so Enemies don’t run into eachother) but what’s happening is that it’s recalculating the path around itself.
ie. The graph is recalculated, and the object is counted as a non-walkable area, so when trying to create a path originating from itself its ON a non-walkable area…
Can you think of anyway for me to stop my npc’s from running into eachother? (Other than buying pro right now )
Stop tempting me haha. I was planning on throwing my game on kickstarter to try to scrape together $100 for a steam greenlight submission but maybe now I’ll have to aim for $200 lol…
Anyways, keep up the great work! (And I’m impressed by the reply time!)
While developing this plugin for a few years, users request A LOT of stuff you never think about yourself
Navmesh cutting is really great. And btw, if you use navmesh cutting along with the RichAI script, it will update the path automatically when the graph is updated (more precisely: when the parts of the navmesh the path goes through is updated).
Hi
Yes, there is a callback for that
`
public void OnEnable () {
AstarPath.active.OnGraphsUpdated += OnGraphsUpdated;
}
public void OnDisable () {
if ( AstarPath.active != null ) {
AstarPath.active.OnGraphsUpdated -= OnGraphsUpdated;
}
}
public void OnGraphsUpdated ( AstarPath ap ) {
// Do stuff
}`
See http://arongranberg.com/astar/docs/class_astar_path.php#a8c6d31ec81922e83c11aaf8a96f33cb2
Oh wow that’s awesome, you really thought of everything! Thanks! Great Plugin!
I also had a look at navmesh cutting which looks like a much better solution, I might have to buy the pro version!
Cheers.