Skip to content

Getting Started (The "Hello World")

Benjamin Sommerfeld edited this page Nov 20, 2025 · 1 revision

You installed the library. Now you want it to do something. Here is the absolute bare minimum to get from A to B without crying.

The Cast

You only need to know five things to get started. Everything else is for people who like over-engineering.

  • PathfinderFactory: Dispenses the algorithm. Currently serves A*, because Dijkstra is for history books.
  • Pathfinder: The engine. It runs the math so you don't have to.
  • PathfinderConfiguration: The knobs and dials. Use this to tune performance or break everything.
  • PathfinderResult: The answer. Did we make it? How do we get there?
  • PathPosition: Just X, Y, Z. Don't overthink it.

Minimal Example

This assumes you have a start and a target. By default, this example assumes an empty void (no walls). If you want to avoid actual obstacles, you need to configure a Provider (see advanced guides).

// 1. Get the factory (A* is king)
PathfinderFactory factory = new AStarPathfinderFactory();

// 2. Use default config. It's faster than whatever you were planning to write.
PathfinderConfiguration config = PathfinderConfiguration.builder().build();

// 3. Ignite the engine
Pathfinder pathfinder = factory.createPathfinder(config);

// 4. Define where you are and where you want to go
PathPosition start = new PathPosition(1, 2, 3);
PathPosition target = new PathPosition(10, 5, 20);

// 5. Fire and forget (Async)
// Note: In a real scenario, pass your EnvironmentContext here.
pathfinder.findPath(start, target).thenAccept(result -> {
    
    if (result.successful()) {
        System.out.println("Easy. Path length: " + result.getPath().size());
        // Do movement logic here
    } else {
        System.err.println("Path failed. Reason: " + result.state());
    }
    
});

That's it. You are now navigating a 3D grid. If you actually have walls, water, or physics, go read the Providers page.

Clone this wiki locally