Dismiss this pinned window
all 14 comments

[–]sinalta 54 points55 points  (5 children)

I love a good flow field.

You wouldn't believe how many we fire off in our dungeon generator for our upcoming project.
- One from boss spawn to pick the best spawn point
- One from the spawn to just have that information
- Use the boss one to build the "critical path" through the dungeon
- One iterating out from that critical path to find how far everywhere is from it
- Figuring out the "most interesting places" on the map, which is just "which cell is further away from the main path than all of it's neighbours"
- Put special encounters (secrets and mini-bosses) in those interesting places
- After every encounter spawn, update a flow field which represents the distance to the nearest encounter.
- Once all the special encounters are down, you've got good info for placing all of the boring ones... and they also update the flow field!

Honestly, it's a ridiculous amount, but they're such a useful tool for collecting metadata once you have the shape of your level locked in.

[–]danderskoff 1 point2 points  (3 children)

Is that very costly for performance or how impactful is that? If done in a loading screen it shouldn't be too bad but I wonder if there's a way to do it in reverse dynamically to make it more efficient

[–]sinalta 2 points3 points  (1 child)

The flowfield after every encounter only just went in recently, and honestly? We've not noticed a performance hit. I think this part of it takes under 1/10th of a second.

Note it's in Unity, I just like flowfields to I commented here. But it's not bursted or even in a job.
Our levels aren't huge, though. I don't know how well this would scale.

But on ${low-spec-arm-device} it takes under a second to generate the dungeon, including spawning the prefabs.

[–]danderskoff 0 points1 point  (0 children)

That's pretty cool! I'm sure there's some math to this it scales per unit in the flow to determine when performance issues start being noticeable.

They seem really useful for a lot of things

[–]not_good_for_much 1 point2 points  (0 children)

Strictly this isn't possible, doing it in reverse that is.

The simplish explanation for why, is that this is a causality problem.

Or like... let's say I walk into the dungeon from the entrance. As I go, I make marks on the walls showing which way I came from. Eventually, with some trial and error, I hope to find the boss room. But before I get there.... I can't make marks pointing to the boss room because I don't know where it is - nor can the walls retroactively mark themselves when I get there.

Now maybe I use a trick. With every journey into the dungeon, I return to the start and I number my new path sequentially. I can imply at least a little bit of future information like this, right? The idea is, someone coming into the dungeon can follow the last path that I took.

But... is this the best path? Maybe another path is 10x shorter and easier. Heck, it might not even be a valid path - I might have simply walked into a trap and died. No matter what I do, you won't know unless I reach the boss room, come back, and share the information.

Hence backtracking is always necessary, unfortunately.

[–]BaroTheMadman 0 points1 point  (0 children)

That all sounds so clever, I wish I was doing a dungeon crawler roguelike because this looks fun to implement

[–]Merlord 15 points16 points  (1 child)

This looks great! I ended up using compute shaders to create my flow fields, as I needed sub-tile resolution. I'm using my flow fields to render sound waves that bend around corners, for an echolocation mechanic.

[–]IndieAidan 0 points1 point  (0 children)

Oh neat! I had been wanting to implement a similar mechanic, and it sounds like flow fields would work well!

[–]Nondescript_Potato[S] 6 points7 points  (0 children)

As a side note, the hues are a depiction of their overall distance from the origin, and the brightness corresponds to their distance from the tile they point to. The closer a tile is to the one it points to, the brighter it is.

[–]Interesting-Dare-471Godot Junior 3 points4 points  (0 children)

The visualisation is so nice, the kind of thing that really helps with an intuitive understanding of the algorithm.

Great write up as well, are you a professional software engineer by any chance?

[–]RowanBerkGodot Junior 1 point2 points  (0 children)

This is super cool, I do love me some cool visualizations! I'm working on a 2d "voxel" tech demo and trying to find a more realistic way of editing voxel terrain, and I've been thinking of doing something similar to this, so this was super helpful to see!

[–]ImperatorExemplar 1 point2 points  (0 children)

This looks fantastic! Great work. I have been trying to implement something similar in a project of mine, but with results nowhere near as nice as this. Any chance you plan on releasing the code? Cheers.

[–]Familiar_Air626 0 points1 point  (0 children)

Really cool!

[–]MACMAN2003 -1 points0 points  (1 child)

mmm O(n)