I will be brief, so ask if I need to give additional details. I am not asking for hand holding - just what components I should look into, vague structure of how to handle things, and simple links or answers like “Try looking at X and Y features.”
I’ve went through some tuts and setup things to work well with a single room (1 tile) but would like to be ready for my larger maps. Make sure I’m in the right direction.
Grid Graphs seem great, and unless I’m mistaken they are also the best choice for me.
Logically, I figured it would be most efficient to have a grid graph for each individual tile, and only update a single tile when a new obstacle is placed on it (ex. Wall spawns, grabs its nearby tiles, and updates them.) This way I am not updating a massive 1000x1000 map anytime a 42x42 section or two needs updated.
However I read in another thread that I should only have 1 graph.
I would prefer to just load the grid graph & not have to worry about more complex logic like loading/unloading sections, unless I have to.
I also noticed grid graph baking is so fast in 0-1ms, I thought of just baking a new grid graph anytime the player moves in a straight line through an obstacle. (raycast straight line, and create graph if ray passes through obstacle). But I may be misunderstanding the debug log A*PP reports in #milliseconds. Performance (not hitching) is vital after the level loads. Input lag (calculating path) shouldn’t be a problem.
I also read an interesting solution here ‘Grid one moves with the player’ and thought this might be simpler? A grid for each PC / NPC? Rescan constantly?
Details
My game is a 2D game in a 3D world, on xz plane. Y is ALWAYS set to 0. No height is ever used. Sprites billboarded to screen, but everything is 3D. I don’t use meshes, just SpriteRenderers, but I do use MeshColliders and PrimitiveColliders.
Performance: My game is PC only, so as long as A* PP doesn’t take hundreds of MB’s, I should be fine. My game is not seamless, so the player loads into each location. This gives me plenty of time to bake navigation on load. This also means the largest location is a single tilemap.
I have two types of game locations. Very large procedurally generated tilemaps, and very small handcrafted locations. I figure the latter will be easy, so I am mostly concerned with the large procedural tilemaps.
How Large: Each tilemap has a size of around 25x25 tiles, with each tile being quite large - 2560x2560 pixels. So each location is at maximum 64k pixels by 64k pixels or units (Unity is set to 1 PixelPerUnit.)
A tile is the ground. A walkable square.
Using a grid graph on a single tile, I found a node size of 60 to work great.
A single Tile has a grid graph size of 42x42 (size 60)
So my maps are around 1050x1050 nodes (size 60)
I do not know if I will ever need to increase the tile size beyond 25x25, but may need to. So may need more than 1k x 1k nodes. Max I ever see using though is double 2k x 2k nodes @ 60. As a side note, I would like to explain to others in a future tutorial on huge open worlds how they can handle things, if I just need an extra step.
USAGE: Very simple. Click-to-move pathfinding for PlayerCharacter or NPC AI (Vector3 position), moving around obstacles (Trees, Bushes, Crates) so simple obstacle avoidance with straight lines otherwise. I thought of not even using pathfinding system, since I mostly just need obstacle avoidance, NPC/PC interaction/avoidance, and preventing out of bounds (off-tile) movement…but would like the player to be able to navigate a long way across fences if the path is within screen view. Although that is rare.
Currently I am using RaycastSmooth to get smooth straight lines when no obstacles are present, combined with SimpleSmooth to have a much smoother obstacle avoidance. Works really well with both on with a Seeker.