So I’m having some difficulties understanding how to properly setup grids for my overhead 2d game. I resolve environmental collisions from an object representing the characters “feet” defined by a rectangular BoxCollider2D (a circular “shadow” in the image below). I’m having a hard time figuring out a definition for graphs that allows the base of my character to correctly clear obstacles without also blocking off tight pathways. Here’s an image of what I’m talking about.
I’ve played with several different node sizes and, erosion iterations, and circle diameters for physics2D testing and can’t seem to find a sweet spot that will allow me to correctly describe the required clearances for the “base” of one of my characters. Any best practices or other assistance would be most appreciated. Would it be possible to add support for a box collider2D as a collider type for collision testing?
Hi
So it looks like your character is not circular at the base? The grid graph can only represent circular characters as the character could have any rotation. Is this the issue you are having?
Generally you should think of the walkable surface of the graph as the surface where every point is a valid position for the pivot point of the character. If you cannot represent this accurately, perhaps you need to increase the resolution of the grid graph.
Yeah my base is a sort of oval shape and that’s the object I need to use to get my pathing measurements. Since my characters don’t rotate I don’t have the constraint of supporting any possible rotation (however now I don understand why the graph is structured the way it is!). I guess I just need to figure out a way to represent the “feet collisions” of my characters with a circular shape. Thanks!
Hi
This package uses the Unity physics engine to check for collisions. So if you want to plug something like that in you could modify that code. See Base.cs and the Check method in the GraphCollision class. You could change the OverlapCircle call to something else that better matches your oval shape. I don’t think there is a good primitive in the physics API, but you could probably approximate it a bit better at least.
Thanks! I was able to get this working by sampling the size of the collider of the bases collider. Where would I go about adding a new enum type to the editor gui dropdown?
I tried adding GraphCollision.ColliderType.Box2D but it appears to need support somewhere else to show up. Where would I go about hooking that up?
How is it recommended to handle having enemies of different sizes? Different graphs for different enemy sizes?
Hi
Nice!
Yes, you will also need to tweak the DrawCollisionEditor method in the GridGeneratorEditor.cs file.
Pretty much, here’s a tutorial about it: Multiple agent types - A* Pathfinding Project