-
Notifications
You must be signed in to change notification settings - Fork 18
Introduction
Pathetic runs on black magic by default. It's optimized for 99% of use cases.
But if you have trust issues, specific terrain requirements (like 3D diagonal movement), or you just want to see your CPU cry, you can take the wheel yourself. Here is how you micromanage the engine.
The following setup changes almost everything. Do not copy-paste this blindly. Use it as a reference for what is possible.
private static Pathfinder constructPathfinder() {
PathfinderFactory pathfinderFactory = new AStarPathfinderFactory();
PathfinderInitializer pathfinderInitializer = new PathfinderInitializerImpl();
PathfinderConfiguration pathfinderConfiguration = PathfinderConfiguration.builder()
// Threading
.async(true) // Blocking the main thread is for amateurs.
// Safety Nets
.fallback(true) // If we fail, give us the "closest" point instead of null.
.maxIterations(1_000_000) // Your CPU might hate you, but the path WILL be found.
.maxLength(200) // Don't path across the entire world map.
// The Brains
.heuristicWeights(HeuristicWeights.create(0.5, 1, 0.7, 0.3)) // Fine-tune the A* bias.
.heuristicStrategy(HeuristicStrategies.SQUARED) // Faster, slightly less accurate.
// Movement Physics
.neighborStrategy(NeighborStrategies.DIAGONAL_3D) // Enable diagonal movement.
// Logic Injection
.nodeCostProcessors(List.of(new BasicCostProcessor())) // Add custom terrain costs (mud, water).
.nodeValidationProcessors(List.of(Validators.not(new BasicValidator()))) // Custom rules for "is this block safe?"
// The World Connection
.provider(new NavigationPointProviderImpl()) // How the engine sees your data.
.build();
return pathfinderFactory.createPathfinder(pathfinderConfiguration, pathfinderInitializer);
}We broke the components down so you can read only what you broke.
-
PathfinderFactory – The entry point. Spawns the engine.
-
Heuristics – Math that guesses the distance. Tweak this if your paths look drunk.
-
Processors - The logic pipeline. Add costs (mud is slow) or validation (lava is bad).
-
Neighbor Strategies – Defines how entities move (Manhattan vs. Diagonal).
-
Providers – Connects the library to your actual world data.