Roblox UtilitiesDevlHub Roblox Documentation

Class

PathfindingService

NotCreatableServiceNotReplicated
Inherits
Instance › Object
Memory category
Instances

Used to find logical paths between two points.

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 Pathfinding for details on implementing character pathfinding.

Properties 1#

EmptyCutofffloatSets the percent of a voxel has to be occupied to be considered empty. Defaults to 0.16.ReadSafeDeprecatedNotReplicated

EmptyCutoff: float#

NotReplicatedDeprecatedReadSafeDeprecated

Deprecated. This property is deprecated, since the legacy pathfinding system using it has since been removed. Do not use it for new work.

This function worked with the legacy pathfinding system. The pathfinding system currently uses a navigation grid and the EmptyCutoff is unused.

When the PathfindingService computes a path using PathfindingService:ComputeRawPathAsync() or PathfindingService:ComputeRawPathAsync() it uses the voxel representation of the world. A voxel is one cube in a grid overlaid on the world. In this case the voxels being used are 4x4x4. This property sets the percent of a voxel has to be occupied to be considered empty. Defaults to 0.16.

Methods 4#

ComputeRawPathAsyncComputes and returns a Path between two Vector3s. If the given MaxDistance is greater than 512, an error will be thrown. (MaxDistance is too large).DeprecatedYields
ComputeSmoothPathAsyncComputes and returns a smooth Path between two Vector3s.DeprecatedYields
CreatePathCreates a Path object based on the given agent parameters.
FindPathAsyncFinds a Path between the two provided points.DeprecatedYields

ComputeRawPathAsync(start: Vector3, finish: Vector3, maxDistance: float): Path#

YieldsDeprecatedDeprecated

Deprecated. This item has been superseded by PathfindingService:FindPathAsync() which should be used in all new work instead.

This function computes and returns a Path between two Vector3s. If the given MaxDistance is greater than 512, an error will be thrown. (MaxDistance is too large).

NameTypeDefaultDescription
startVector3
finishVector3
maxDistancefloat
Returns

ComputeSmoothPathAsync(start: Vector3, finish: Vector3, maxDistance: float): Path#

YieldsDeprecatedDeprecated

Deprecated. This item has been superseded by PathfindingService:FindPathAsync() which should be used in all new work instead.

This function computes and returns a smooth Path between two Vector3s. This function fulfills the same purpose as PathfindingService:ComputeRawPathAsync(), but creates a much smoother path for an NPC to follow in comparison.

NameTypeDefaultDescription
startVector3
finishVector3
maxDistancefloat
Returns

CreatePath(agentParameters: Dictionary = nil): Path#

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 Class.TrussPart|TrussParts during pathfinding is allowed.
WaypointSpacing number 4 Determines the spacing between intermediate waypoints in path.
Costs table {} Table of materials or defined Class.PathfindingModifier|PathfindingModifiers and their "cost" for traversal. Useful for making the agent prefer certain materials/regions over others.
NameTypeDefaultDescription
agentParametersDictionarynilLua table which lets you fine-tune the path based on various agent parameters.
Returns

FindPathAsync(start: Vector3, finish: Vector3): Path#

YieldsDeprecated

Deprecated. This function has been superseded by the sequential method of calling PathfindingService:CreatePath() followed by Path. This lets you create a Path object using various custom parameters and then compute or re-compute a path on the same object if any dynamic changes within the place block the path.

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.

NameTypeDefaultDescription
startVector3Path start coordinates.
finishVector3Path finish coordinates.
Returns

Inherited members#

Inherited from Instance 58
Inherited from Object 6
Properties (2)

ClassName, className

Events (1)

Changed