WarFrontIO / client

Real-time strategy game played in the browser
https://dev.warfront.io
MIT License
20 stars 6 forks source link

Improve boat pathfinding #14

Open platz1de opened 2 months ago

platz1de commented 2 months ago

There are a few changes that could be made to improve the pathfinding of boats (to produce more natural looking paths)

Adjusting border nodes

The border nodes of areas (mostly 50x50 tiles) are currently always the outermost two positions which allow transition between the area and it's neighbor. Adjusting this behaviour to:

should produce smoother paths

Respect speed in precalculations

The proprocessed paths are currently only chosen based on distance. This could be optimized to favor paths with a minimal amount of "turns". To make it actually useful, pathfinding would need to support more than 8 directions (maybe 32). We don't need an optimal solution, so handling them as currently while saving possible offsets should be enough

Additional complexity arrises from corner nodes. Here the boats could arrive/exit from/to three directions with different rotations, so every corner node needs to be handled three times. This increases preprocess time a lot. A possible simplification would need to be discussed here.

Actually use waypoints to turn boats

The current behaviour of boats was already designed with this in mind. Boats should start turning whenever they reach a waypoint, making a small curve in the direction of the next one. Since waypoints are only spaced more than one tile in free-water areas anyways, this won't produce any problems with land collisions