Gorilla.Utils.Pathfinding Unit Reference
Overview
The Gorilla.Utils.Pathfinding unit provides the base pathfinding framework for Gorilla3D. It defines TGorillaPathfindingAlgorithm, an abstract base class that manages obstacles, an agent, and obstacle margins. The actual A* algorithm is implemented in Gorilla.Utils.Pathfinding.AStar.
Class Hierarchy
TComponent
└── TControl3D
└── TGorillaControl
└── TGorillaPathfindingAlgorithm
└── TGorillaPathfindingAStar (in Gorilla.Utils.Pathfinding.AStar)
Exception Classes
EPathFindingException = class(Exception); // General pathfinding error
EPathFindingAbort = class(EAbort); // Pathfinding abort (silent)
Callback Types
TOnPathfindingObstacleUpdate = procedure(const AControl: TControl3D;
out ABounds: TBoundingBox) of object;
Records
TGorillaPathfindingObstacle
Structure storing information about each obstacle.
| Field |
Type |
Description |
Control |
TControl3D |
The visual component acting as obstacle |
IsStatic |
Boolean |
If True, bounding box is computed once (better performance) |
Bounds |
TBoundingBox |
Current bounding box |
Computed |
Boolean |
Whether grid rect has been calculated |
GridRect |
TRectF |
Computed grid coordinates |
Methods
| Method |
Description |
Create(AControl, AIsStatic) |
Constructor |
Reset() |
Reset computed state, forcing recalculation |
TGorillaPathfindingAlgorithm
Abstract base class for pathfinding algorithms. Manages obstacles and the navigating agent.
Published Properties
| Property |
Type |
Description |
Agent |
TControl3D |
The character/NPC that navigates |
ObstacleMargin |
TPoint3D |
Buffer zone around obstacles (e.g., (0.5, 0, 0.5)) |
OnUpdate |
TOnPathfindingObstacleUpdate |
Custom bounding box callback for obstacles |
Public Properties
| Property |
Type |
Description |
AgentPosition |
TPoint3D |
Current agent position (returns (0,0,0) if no agent) |
Public Methods
| Method |
Description |
AddObstacle(ACtrl, AIsStatic) |
Add obstacle with auto bounding box |
AddObstacle(ACtrl, ABounds, AIsStatic) |
Add obstacle with explicit bounding box |
RemoveObstacle(ACtrl) |
Remove a specific obstacle |
ClearObstacles() |
Remove all obstacles |
ResetObstacles() |
Reset computed grid rects (force recalculation) |
CountObstacles() |
Return number of registered obstacles |
TGorillaPathfindingAStar
A* pathfinding implementation (in Gorilla.Utils.Pathfinding.AStar). Extends TGorillaPathfindingAlgorithm with grid-based pathfinding that finds the shortest path from agent to target while avoiding obstacles.
Usage
uses Gorilla.Utils.Pathfinding, Gorilla.Utils.Pathfinding.AStar;
var Pathfinder := TGorillaPathfindingAStar.Create(Self);
Pathfinder.Parent := GorillaViewport1;
Pathfinder.Agent := CharacterModel;
// Add obstacles
Pathfinder.AddObstacle(WallMesh, True); // static
Pathfinder.AddObstacle(MovingPlatform, False); // dynamic
Pathfinder.ObstacleMargin := Point3D(0.5, 0, 0.5);
See Also