PathfindingService
PathfindingService is used to find logical paths between two points, ensuring that characters can move between the points without running into walls or other obstacles. By default, the shortest path is calculated, but you can implement pathfinding modifiers to compute smarter paths across various materials, around defined regions, or through obstacles.
See Character Pathfinding for usage details.
Summary
Properties
Methods
Finds a Path between the two provided points.
Events
Properties
Methods
CreatePath
Creates a Path object based on various agent parameters. Valid keys and values in the agentParameters table are as follows:
Key | Type | Default | Description |
---|---|---|---|
AgentRadius | integer | 2 | Determines the minimum amount of horizontal space required for empty space to be considered traversable. |
AgentHeight | integer | 5 | Determines the minimum amount of vertical space required for empty space to be considered traversable. |
AgentCanJump | boolean | true | Determines whether jumping during pathfinding is allowed. |
AgentCanClimb | boolean | false | Determines whether climbing TrussParts during pathfinding is allowed. |
WaypointSpacing | number | 4 | Determines the spacing between intermediate waypoints in path. |
Costs | table | {} | Table of materials or defined PathfindingModifiers and their "cost" for traversal. Useful for making the agent prefer certain materials/regions over others. See here for details. |
Parameters
Lua table which lets you fine-tune the path for the size of the agent (the humanoid that will move along the path). See above for valid keys, types, and descriptions.
Returns
Code Samples
local PathfindingService = game:GetService("PathfindingService")
local path = PathfindingService:CreatePath({
AgentRadius = 3,
AgentHeight = 6,
AgentCanJump = false,
Costs = {
Water = 20
}
})
FindPathAsync
This function is used to find a Path between two provided points. This path uses the navigation grid created by PathfindingService and makes sure that the path can be followed by a regular-sized Roblox character.
This function returns a Path object which contains the coordinates of the path. If no path is found between the two points, this function will still return a Path object, but that object's Path.Status will be PathStatus.NoPath.
To get the waypoints of a Path object, you can use the Path:GetWaypoints() function.