Hi I am having a problem with my path finding as you can see in the video
robloxapp-20231216-1013517.wmv (1.3 MB)
My code:
local PFS = game:GetService("PathfindingService")
function showPath(path)
local waypoints = path:GetWaypoints()
for _, waypoint in ipairs(waypoints) do
local part = Instance.new("Part", game.Workspace)
part.Shape = Enum.PartType.Ball
part.Material = Enum.Material.Neon
part.Anchored = true
part.CanCollide = false
part.Size = Vector3.new(1,1,1)
part.Position = waypoint.Position
game:GetService("Debris"):AddItem(part, .5)
end
end
function createPath(model, target)
local agentParams = {
AgentHeight = 2.5,
AgentRadius = 2,
AgentCanJump = true
}
local path = PFS:CreatePath()
local waypoints = path:GetWaypoints()
path:ComputeAsync(model.PrimaryPart.Position, target)
if path.Status == Enum.PathStatus.Success then
local wayPoints = path:GetWaypoints()
return path, wayPoints
end
end
function main(model, target)
local path, waypoints = createPath(model, target)
if path and waypoints then
print(path, waypoints)
--showPath(path)
for _, waypoint in ipairs(waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
model.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
model.Humanoid:MoveTo(waypoint.Position)
end
end
end
game:GetService("RunService").Stepped:Connect(function()
main(script.Parent,game.Workspace.End.Position)
end)