local PathfindingService = game:GetService("PathfindingService")
local endpoint = workspace.endpoint
local startpoint = workspace.startpoint
local path = PathfindingService:CreatePath()
path:ComputeAsync(startpoint.Position, endpoint.Position)
local waypoints = path:GetWaypoints()
local Folder = Instance.new("Folder")
Folder.Name = "Waypoints"
Folder.Parent = workspace
for i, v in ipairs(waypoints) do
local Part = Instance.new("Part")
Part.Position = v.Position
Part.Anchored = true
Part.Size = Vector3.new(1, 1, 1)
Part.Parent = Folder
if (i > 1) then
local lastWaypoint = waypoints[i - 1]
local dist = (v.Position - lastWaypoint.Position).Magnitude
local Part2 = Instance.new("Part")
Part2.Anchored = true
Part2.BrickColor = BrickColor.Black()
Part2.Size = Vector3.new(.5, .5, dist)
Part2.CFrame = CFrame.new(lastWaypoint.Position, v.Position) * CFrame.new(0, 0, dist / -2)
Part2.Parent = Folder
end
end
Yes, But how would I tween the start point to all of the waypoints?
Because it does not reach the lasy waypoint
local PathfindingService = game:GetService("PathfindingService")
local TweenService = game:GetService("TweenService")
local endpoint = workspace.endpoint
local startpoint = workspace.startpoint
local path = PathfindingService:CreatePath()
path:ComputeAsync(startpoint.Position, endpoint.Position)
local waypoints = path:GetWaypoints()
local Folder = Instance.new("Folder")
Folder.Name = "Waypoints"
Folder.Parent = workspace
for i, v in ipairs(waypoints) do
local Part = Instance.new("Part")
Part.Position = v.Position
Part.Anchored = true
Part.Size = Vector3.new(1, 1, 1)
Part.Parent = Folder
if (i > 1) then
local tweenInfo = TweenInfo.new(
1, -- Time
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
0, -- RepeatCount (when less than zero the tween will loop indefinitely)
false, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
local lastWaypoint = waypoints[i - 1]
local tween = TweenService:Create(startpoint, tweenInfo, {Position = lastWaypoint.Position})
tween:Play()
local dist = (v.Position - lastWaypoint.Position).Magnitude
local Part2 = Instance.new("Part")
Part2.Anchored = true
Part2.BrickColor = BrickColor.Black()
Part2.Size = Vector3.new(.5, .5, dist)
Part2.CFrame = CFrame.new(lastWaypoint.Position, v.Position) * CFrame.new(0, 0, dist / -2)
Part2.Parent = Folder
end
end
the lastWaypoint variable represents the previous waypoint in the iteration, not the current one. Set the Position to v.Position when you create the Tween.
local PathfindingService = game:GetService("PathfindingService")
local TweenService = game:GetService("TweenService")
local TweenInfoNew = TweenInfo.new(
5, -- Time
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
0, -- RepeatCount (when less than zero the tween will loop indefinitely)
false, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
local endpoint = workspace.endpoint
local startpoint = workspace.startpoint
local path = PathfindingService:CreatePath()
path:ComputeAsync(startpoint.Position, endpoint.Position)
local waypoints = path:GetWaypoints()
local Folder = Instance.new("Folder")
Folder.Name = "Waypoints"
Folder.Parent = workspace
for i, v in ipairs(waypoints) do
local Part = Instance.new("Part")
Part.Position = v.Position
Part.Anchored = true
Part.Size = Vector3.new(1, 1, 1)
Part.Parent = Folder
if (i > 1) then
local lastWaypoint = waypoints[i - 1]
local dist = (v.Position - lastWaypoint.Position).Magnitude
local tween = TweenService:Create(startpoint, TweenInfoNew, {Position = lastWaypoint.Position})
tween:Play()
local Part2 = Instance.new("Part")
Part2.Anchored = true
Part2.BrickColor = BrickColor.Black()
Part2.Size = Vector3.new(.5, .5, dist)
Part2.CFrame = CFrame.new(lastWaypoint.Position, v.Position) * CFrame.new(0, 0, dist / -2)
Part2.Parent = Folder
end
end