> For the complete documentation index, see [llms.txt](https://runemate.gitbook.io/runemate-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://runemate.gitbook.io/runemate-documentation/api/game-world/global-pathfinding.md).

# Global Pathfinding

The **Pathfinder** is a new system that is capable of building a `Path` that can traverse across the game world, handling the majority of teleports and transports.

&#x20;Ideally, only one **Pathfinder** instance should be created per bot session - this instance registers a few listeners with the **EventDispatcher**, and is responsible for monitoring the context used to build paths. This context tracks things like the items you have on your character, the quests it has completed, and other essential information for finding the most optimal path.

## Pathfinding

The bot can use two different algorithms to calculate paths, [Dijkstra's](https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm) and [A\*](https://en.wikipedia.org/wiki/A*_search_algorithm). Dijkstra's Algorithm should always return the shortest path, but that accuracy comes at the cost of speed. A\* is a more efficient algorithm, but may result in less accurate paths. The default algorithm used is A\*.

## Walking

As you will see in the usage guide, the **Path** computed by **findPath()** is fully re-usable until it is invalidated (either by straying too far from it, or being unable to continue along it). The last Path generated will be accessible via **Pathfinder#getLastPath()**.

As with other Path implementations, **TraversalOption**s can be passed to the **step()** method to change the walking behavior. For example, passing **TraversalOption.USE\_DIRECT\_INPUT** will allow the walking API to use Direct Input.

## Usage

The library is automatically added to your project when using the RuneMate Gradle plugin (from v1.4.X).

The recommended approach is to create and store an instance of **Pathfinder** in your bot main class (or some other path management class) and ensuring that you only create one instance per instance of your bot.

The PathBuilder (via **Pathfinder#pathBuilder()**) allows for both the start and destination position(s) to be configured, as well as configuring the transports/teleports that are accessible to the pathfinding algorithm. Most notable of these is the **#poh()** method which configures the pathfinder with the teleports available when using the player's POH.

Here is an example usage:

<pre class="language-java"><code class="lang-java">private Pathfinder pathfinder;

@Override
public void onStart(String... args) {
    pathfinder = Pathfinder.create(this);
}

@Override
public void onLoop() {
    Coordinate destination = /* your destination */;
    Path path;
    if (pathfinder.getLastPath() != null &#x26;&#x26; pathfinder.getLastPath().isValid()) {
        path = pathfinder.getLastPath();
    } else {
        path = pathfinder.pathBuilder()
            .preferAccuracy()
            .enableMinigameTeleports(false)
            .poh(POH.builder()
                .mountedGlory(true)
                .mountedXericsTalisman(true)
                .jewelleryBoxTier(JewelleryBox.Tier.ORNATE)
                .nexusPortal(Portal.BARROWS)
                .build())
            .destination(destination)
            .findPath();
    }
    
    if (path != null) {
        path.step();
    }
<strong>}
</strong></code></pre>

{% hint style="warning" %}
The **Pathfinder** must not be created before **onStart**, as it needs to register listeners to track context.
{% endhint %}

## Contributing

Similar to the Game API, the Pathfinder API is fully open-source, and the code can be found on the [RuneMate Community GitLab](https://gitlab.com/runemate/community/runemate-pathfinder-api). We encourage developers to submit changes as required to expand our coverage of the game map.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://runemate.gitbook.io/runemate-documentation/api/game-world/global-pathfinding.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
