Hello,
All I want to know is how I can transfer the waypoints of the bèzier cuve so the NPC walks on it.
I already have both scripts but I don’t know how to add them together so the NPC will walk on the waypoints created by the bèzier curves.
ServerScript for the bèzier curves:
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
Script that I had for pathfinding:
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()
This script doesn’t works though… It did work but now it didn’t worked probably cause I tried to use the curve but now its messed up.
Anyways if you could help me that would be awesome!