I’m trying to create entities similar to doors. I figured I should have a waypoint at the beginning and end of rooms, and then have entities pathfind to them, but I’m having trouble because the entity is two separate parts.
local TweenService = game:GetService("TweenService")
local Pathfinding = game:GetService("PathfindingService")
local waypoints = workspace.waypoints:GetChildren()
task.wait(5)
local Speed = 35
local Path = Pathfinding:CreatePath({
AgentRadius = 2,
AgentHeight = 2,
})
local GeneratedWaypoints
-- script.Parent.Position - v.Position).Magnitude / Speed
for i, v in pairs(waypoints) do
local success, errorMsg = pcall(function()
Path:ComputeAsync(script.Parent.Position, v.Position)
end)
if success and Path.Status == Enum.PathStatus.Success then
GeneratedWaypoints = Path:GetWaypoints()
for i, v in pairs(GeneratedWaypoints) do
local Tween = TweenService:Create(script.Parent, TweenInfo.new((script.Parent.Position - v.Position).Magnitude / Speed, Enum.EasingStyle.Linear), {Position = v.Position})
Tween:Play()
Tween.Completed:Wait()
end
end
end
Video of problem:
Any work arounds/solutions?