A* Pathfinding Project

Assigning tags with collision testing


#1

Hi there!

I am positive that this has been answered somewhere, but I am obviously struggling to find the correct wording. I am hoping to be able to assign tags in the same way collision testing works. Basically selecting a layer (or layers) that should use a particular tag. (I’m using 2D physics.)

My maps are quite large, and frequently changing as we develop the game, so manually drawing out the shapes would be a real time sink. However they do have 2D physics colliders generated, so if I can use those it would be much nicer! Is there a way to set this up?

Ideally I’d love to be able to put an additional class on the Astar Path GameObject that then has it assign tags once it’s done detecting global obstacles!

Thanks!


#2

Hey,

You would have to modify the generator scripts for this to work. It’s not too difficult to do (I needed it for our project also)

Or write your own generator, you can read more about that here: https://arongranberg.com/astar/docs/old/writing-graph-generators.php


#3

Thanks for the reply!

Writing my own generator seems like overkill, considering I need all of the functionality of the GridGenerator? But reading through GridGenerator, I wonder if I could override RecalculateCell (duplicating the same code), but after it calculates node.Walkable (line 1220) I would then do further Physics tests on node.position to then assign the node relevant tags?

My concern is I might be looking at this too closely, and actually be in the wrong area? Particularly the note on the method’s comment: This will not recalculate any connections as this method is often run for several adjacent nodes at a time.

Is this something I should be concerned about? Am I even in the right area? Haha.


#4

Hey,

Alternatively you could do this also in a post scan script. If you’re only scanning from the editor. Since this would cause a bit of delay.

Once the scan is complete you could do a raycast down from each node and get the tag of the object underneath. Based on this the tag of the node could be assigned.

This would require much less inner code changes but yield a similar result.


#5

Hi

The RecalculateCell code is the right place to do this.
Or you could do like @ToastyStoemp suggests in his last post.


#6

@stuntboots while I was looking through some source code I ended up reading up on the GraphModifiers, this would be a great start also for what you’re trying to achieve here.

the OnPostScan() function can be used to run some simple code after the scan is completed , read more about the graph modifier here: https://arongranberg.com/astar/docs/graphmodifier.html

Ps. I did also make a Feature request to make the Check Collision and Check Height functions virtual. ( especially for the grid and layered grid graphs) This would make editing the core system much easier. And keep it simple to upgrade once a new version rolls out.