Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Pathfinding AI, follow nearest player issues?

Asked by 5 years ago

Here's the code for reference:

--script for pathfinding enemy to player
local torso = script.Parent.UpperTorso
    local position = torso
    local lowest = math.huge
    local NearestPlayer = nil
    for i, v in pairs(game.Players:GetPlayers()) do
    if v and v.Character then

        local distance = v:DistanceFromCharacter(position)
        if distance < lowest then

            lowest = distance 
            NearestPlayer = v
        end
    end
    end

local humanoid = script.Parent
local finishPosition = NearestPlayer
local path = game:GetService("PathfindingService"):ComputeRawPathAsync(torso.Position, finishPosition, 512)
points = path:GetPointCoordinates()




while true do


-- make sure the old points are gone
game.Workspace.Points:ClearAllChildren()

for p = 1, #points do

    part = Instance.new("Part")
    part.Anchored = true
    part.Size = Vector3.new(1,1,1)
    part.FormFactor = Enum.FormFactor.Symmetric
    part.Parent = game.Workspace.Points
    part.Position = points[p]
    part.BrickColor = BrickColor.Gray()

end

wait(0.1)
end

How do I make finishPosition be put as the End of the pathfinding?

0
if you guys need more clearance I'd be glad to provide, thank you in advance. aoaoaoaoa00 4 — 5y
0
yes, we need all the clearance we can get ihatecars100 502 — 5y

Answer this question