MatejSloboda / Dijkstra_map_for_Godot

MIT License
78 stars 13 forks source link

"Terrain" for connections between points #106

Closed AlexanderPruss closed 3 years ago

AlexanderPruss commented 3 years ago

Background

First off, awesome project! I was looking for something like this for a tactics game I'm building in Godot :)

Djikstra maps consist of points and connections between points. Adding a terrain to a point lets you change the weight of connections to that point in a recalculate() call without having to construct a second DijkstraMap.

I'd like to generalize this concept and also add a "terrain" to connections between points, rather than just to points themselves.

Problem I want to solve

Suppose I have a grid where every single cell has the same terrain, Grass. However, there obstacles between some of these cells - low fences, say. I want the pathfinding weight of connections with this obstacle to be different for different units. As an example -

Proposed Solution

Adding a "terrain" to connections between points and an optional set of weights used for connection-terrain in the recalculate() method would allow the same Dijkstra map to be used for calculating pathfinding for units that react differently to obstacles between cells. It could look something like this:

As connections already have a weight, the weight from the obstacle terrain would act as a multiplier on the cost of traversing that path.

Current Workaround

This is actually currently possible with this addon, but only by kind of abusing the API.

Suppose we have a cell X and a cell Y and we want to create an obstacle between them. To do this, we:

MatejSloboda commented 3 years ago

The "workaround" you mention is the intended way to implement the feature you want. I've considered "terrain per point" vs. "terrain per connection" early in development in #10 and decided on the former, specifically because this "workaround" is possible.

AlexanderPruss commented 3 years ago

Thanks for the quick response, we can probably close this issue then. I'd be happy to add a description of the intended solution for connection terrain to the docs if you'd like.

MatejSloboda commented 3 years ago

Thanks! We are planning to add library of pre-made wrapper objects/examples for most common use-cases. We might want to add this one to the list. I'm not sure how it is going, as I was rather busy with life stuff lately.