arnemileswinter / godot-tilemap-flowfields

Plugin to generate flowfields from tilemaps in the Godot Engine!
Other
28 stars 2 forks source link
ai game-development godot pathfinding

Godot Tilemap Flowfields

RTS-Style optimized path-finding for crowds of agents. Built for the Godot game engine, written with performance in mind in Rust with godot-rust.

Screenshot 1

Installation

Download this repository as zip and unpack to your game folder. Its not yet currently on the Godot asset place.

Usage

Create a "FlowFieldGenerator" node and assign to it the TileMap you wish to use. For each tile, a "FlowFieldTileCost" node must be added as a child Node of the Generator.

Note that currently only Euclidean Path-Finding is implemented.

If you require a different approach, feel free to open an issue or contribute! :)

AdHoc flow field calculation

Use $FlowFieldGenerator.calculate_flow_field(to : Vector2) to retrieve a flow field towards the target vector. Note that this to vector must be in tile-space of your tile-map. Transfer coordinate systems with TileMap.world_to_map and TileMap.to_local accordingly, before invocation.

The return-value supports a function flow(to: Vector2) (with to also in map-space) to query the calculated flow field from the agent's position.

Open the Example Scene to see it all in action.

Baked flow field calculation

With $FlowFieldGenerator.bake_flow_fields() you receive an instance of BakedFlowFields supporting the Function flow_from_to(from:Vector2,to:Vector2), with all flow-fields cached. Pathfinding is then happening in constant time.

Baking all flow-fields creates huge files, however, and is also not recommended for scenarios where your game map changes dynamically. It is recommended to use $FlowFieldGenerator.calculate_flow_field(to : Vector2). Only use baked fields if your map is static and fast-paced path-finding is essential.

The Baked Example Scene is an example on how to save your baked flow-field as a resource.

Platforms

Currently Linux/X11 x86_64 and windows-x64 is officially compiled. If you have the resources to build for darwin or other targets, please don't hesitate to open a PR!

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request
Screenshot 2

Compiling

A justfile is provided: development binaries are built with just, releasing is done via just build-release. The Godot editor must be closed prior to building, else it segfaults because the FlowfieldGenerator is a tool-script.

Known Issues