[Unsolved!] How to add your customized waypoints to PathFinding

Hello,

So I have waypoints created by a bèzier curve but now I need to know how I can get those points and make the NPC walk on the calculated path.

This is the bèzier curve script:

local pointsFolder = workspace.Points

local startPoint = game.Workspace.Dummy.HumanoidRootPart
local endpoint = pointsFolder.End

local middlePoint = pointsFolder.Middle

local function LinearBezier(start, finish, t)
	local range = finish-start

	return start + range*t


end

local function ConstructLinearBezier(start, finish)
	local range = finish-start
	return function(t)
		return start + range*t
	end
end




local function Point(position)
	local part = script.Point:Clone()
	part.CFrame = CFrame.new(position)
	part.Parent = workspace
	part.Anchored = true
	
	return part

end

local Line1 = ConstructLinearBezier(startPoint.Position, middlePoint.Position)
local line2 = ConstructLinearBezier(middlePoint.Position, endpoint.Position)


for t = 0, 1, 0.1 do
	local x1 = Line1(t)
	local x2 = line2(t)

	Point(x1)
	Point(x2)

	Point(LinearBezier(x1, x2, t))

end

And this is the pathfinding script:

local animation = script:WaitForChild("Animation")
local humanoid = script.Parent:WaitForChild("Humanoid")
local clip = humanoid:LoadAnimation(animation)
clip.Looped = true


local pfs = game:GetService("PathfindingService")

local human = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("HumanoidRootPart")

local path = pfs:CreatePath()
path:ComputeAsync(torso.Position, game.Workspace.AIParts.HouseSet.Destination.PrimaryPart.Position)

local waypoints = path:GetWaypoints()


for i, waypoint in pairs(waypoints) do
	human:MoveTo(waypoint.Position)
	human.MoveToFinished:Wait()
	clip:Play()
end

human:MoveTo(game.Workspace.AIParts.HouseSet.Destination.PrimaryPart.Position)
clip:Stop()

Please help me with this!

I just combined those 2 scripts together but now it sets the position of the spheres that are being cloned to 0,0,0. Which I don’t understand why that happens. Also it only clones it twices and the NPC still doesn’t moves.

I fixed some stuff and now this is the current script



local pointsFolder = workspace.Points

local startPoint = game.Workspace.Dummy.HumanoidRootPart
local endpoint = pointsFolder.End

local middlePoint = pointsFolder.Middle

local function LinearBezier(start, finish, t)
	local range = finish-start

	return start + range*t


end

local function ConstructLinearBezier(start, finish)
	local range = finish-start
	return function(t)
		return start + range*t
	end
end





local human = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("HumanoidRootPart")




local part

local function Point(position)

	part = game:GetService("ServerStorage").Point:Clone()
	part.Parent = workspace
	part.CFrame = CFrame.new(position)

	part.CanCollide = false
	part.Anchored = true
	
	
	

	human:MoveTo(part.Position)
	human.MoveToFinished:Wait()


	return part



end

local Line1 = ConstructLinearBezier(startPoint.Position, middlePoint.Position)
local line2 = ConstructLinearBezier(middlePoint.Position, endpoint.Position)


for t = 0, 1, 0.1 do
	local x1 = Line1(t)
	local x2 = line2(t)


	Point(x1)
	Point(x2)

	Point(LinearBezier(x1, x2, t))
	
end



But ofcourse there are some problems with it cause now it does generates the bèzier curve but very very slowly and the NPC still doesn’t moves to the sphere…

1 Like