Pathfinder正在使我的NPC只跟随我的最旧的位置

我正在尝试制作一个迷宫/恐怖游戏。我在Roblox库中使用了一个在线模板作为我的敌人。我使用了下面的代码中的路径查找器。它像它应该的那样找到了我,除了它只去了我的最后一个位置。正如你在下面的图片中看到的,它完全跳过了我,去了我的最后一个位置,然后开始追逐我。我不知道它为什么只去我的最后一个位置,而不是我的当前位置。

local PathFindingS = game:GetService("PathfindingService")
local humanoid = script.Parent:WaitForChild("Humanoid")
local rootPart = script.Parent:WaitForChild("HumanoidRootPart")
local Players = game:GetService("Players")
game.Workspace.Fruity.Humanoid.WalkSpeed = 60

--计算路径
while wait() do

    for i, player in pairs(game.Players:GetPlayers()) do
        local character = game.Workspace:WaitForChild(player.Name)
        local characterPos = character.PrimaryPart.Position
        local path = PathFindingS:CreatePath()
        path:ComputeAsync(rootPart.Position, characterPos)
        game.Workspace.Fruity.HumanoidRootPart:SetNetworkOwner(nil)

        local waypoints = path:GetWaypoints()

        for i, waypoint in pairs(waypoints) do
            local part = Instance.new("Part")
            part.Shape = "Ball"
            part.Material = "Neon"
            part.Size = Vector3.new(0.6,0.6,0.6)
            part.Position = waypoint.Position + Vector3.new(0,2,0)
            part.Anchored = true
            part.CanCollide = false
            part.Parent = game.Workspace
            humanoid:MoveTo(waypoint.Position)
            humanoid.MoveToFinished:Wait()
        end
    end
end

在此输入图片描述

点赞