Pathfinding Service unable to create a path on smooth terrain.
In-game and in Studio the pathfinding bug occurs. This bug is presented when I attempt to create a path using two parts and it goes over smooth terrain.
It’s not cost-related to my knowledge and has been reproduced by various other developers I know.
This happens 100% of the time for me, and others have this issue too.
Code for command bar:
local Pathfinding = require(game.ServerScriptService.Services.PathfindingService)
local waypoints = Pathfinding.CalculatePath(game.Selection:Get()[1].Position, game.Selection:Get()[2].Position, 100):GetWaypoints()
if workspace:FindFirstChild("MessAround") then
workspace.MessAround:Destroy()
end
Instance.new("Folder", workspace).Name = "MessAround"
for i,waypoint in ipairs(waypoints) do
local part = Instance.new("Part", workspace.MessAround)
part.Material = Enum.Material.Neon
part.Anchored = true
part.Position = waypoint.Position
part.Archivable = false
local v = (255 / #waypoints) * i
part.Color = Color3.fromRGB(v, v, 255)
part.Size = Vector3.new(0.5,0.5,0.5)
end
PathfindingService.lua (Services Folder)
local PathfindingService = game:GetService("PathfindingService")
local module = {}
--[=[
@method CalculatePath
@within PathfindingService
@server
Uses roblox's PathfindingService to calculate a path for AI Cars to follow to go from point A to B.
@param start Vector3 -- The initial point the vehicle will move from
@param destination Vector3 -- The point the vehicle will end at
@param DangerNumber number -- The higher, the more likely it is to follow road rules.
@return Path | nil -- The path class will be returned.
]=]
module.CalculatePath = function(start: Vector3, destination: Vector3, DangerNumber: number)
local path = PathfindingService:CreatePath({
Costs = {
--DangerZone = DangerNumber,
Grass = math.huge,
LeafyGrass = math.huge,
Concrete = math.huge,
Plastic = 4
},
AgentCanJump = true,
AgentCanClimb = true,
WaypointSpacing = 100,
AgentHeight = 5,
AgentRadius = 5
})
path:ComputeAsync(start, destination)
if path.Status == Enum.PathStatus.Success then
return path
end
print(path)
end
return module
Steps to Reproduce:
- Create two parts.
- Run the command bar code, you’ll need to create the Pathservice module OR combine it within your code.
- It’ll generate a path for non-terrain based paths, for smooth terrain it’ll error as no path is produced.
This is usually if terrain is elevated, however instances of flat terrain have occurred aswell.
This error occurs with or without Costs in the experience.
Evidence
This is what is generated from an experience I am a developer on:
Without Terrain
With Terrain
Another example that was errored
Many thanks.