PathfindingService

Show Deprecated
Not Creatable
Service
Not Replicated

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

CreatePath(agentParameters: table): Instance  


FindPathAsync(start: Vector3, finish: Vector3): Instance  YIELDS

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:

KeyTypeDefaultDescription
AgentRadiusinteger2Determines the minimum amount of horizontal space required for empty space to be considered traversable.
AgentHeightinteger5Determines the minimum amount of vertical space required for empty space to be considered traversable.
AgentCanJumpbooleantrueDetermines whether jumping during pathfinding is allowed.
AgentCanClimbbooleanfalseDetermines whether climbing `Class.TrussPart|TrussParts` during pathfinding is allowed.
WaypointSpacingnumber4Determines the spacing between intermediate waypoints in path.
Coststable{}Table of materials or defined `Class.PathfindingModifier|PathfindingModifiers` and their "cost" for traversal. Useful for making the agent prefer certain materials/regions over others. See here for details.

Parameters

agentParameters: table

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.

Default Value: "nil"

Returns

A Path object.

Code Samples

LocalScript

local PathfindingService = game:GetService("PathfindingService")
local path = PathfindingService:CreatePath({
AgentRadius = 3,
AgentHeight = 6,
AgentCanJump = false,
Costs = {
Water = 20
}
})

FindPathAsync

Yields

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.

Parameters

start: Vector3

Path start coordinates.

finish: Vector3

Path finish coordinates.


Returns

A Path object.

Events