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

Pathfinding service doesnt do jumps?

Asked by 5 years ago

I am trying to make a pathfinding zombie, but it doesn't handle jumps very well. The new FindPathAsync I know for sure can do jumps, but I can't figure out how to use it, so I'm using getRawPathASync.

Heres a link to a photo: https://totallypalehideout.tumblr.com/image/174606148248

And heres my code:

wait(3)
local pathfindService = game:GetService("PathfindingService")
local PlayerService = game:GetService("Players")
local localCharacter = script.Parent
local start = localCharacter.Torso
local PointModel = Instance.new("Model")
PointModel.Parent = game.Workspace
PointModel.Name = "Points"
pointModel = game.Workspace.Points

local function FindClosestPlayer(inRange)
    local playerDistance, closestPlayer = inRange
    for _, player in pairs(PlayerService:GetPlayers()) do
        local character = player.Character
        local blip = character:FindFirstChild("HumanoidRootPart")
        if blip and character.Parent and character ~= localCharacter then
            local blipDist = (start.Position - blip.Position).Magnitude
            if blipDist <= inRange and blipDist < playerDistance then
                playerDistance, closestPlayer = blipDist, player
            end
        end
    end
    return closestPlayer, playerDistance
end


while true do
    chosenPlayer = FindClosestPlayer(10000)
    if chosenPlayer then
        if chosenPlayer.Character.Humanoid.Health ~= 0 then
            local path = pathfindService:ComputeRawPathAsync(start.Position, chosenPlayer.Character.LowerTorso.Position, 10000)
            local points = path:GetPointCoordinates()

            if points[6] then
                part = Instance.new("Part")
                part.FormFactor = Enum.FormFactor.Custom
                part.Size = Vector3.new(1, 1, 1)
                part.Transparency = 1
                part.Position = points[6]
                part.Anchored = true
                part.CanCollide = false
                part.Parent = pointModel
            elseif points[5] then
                part = Instance.new("Part")
                part.FormFactor = Enum.FormFactor.Custom
                part.Size = Vector3.new(1, 1, 1)
                part.Transparency = 1
                part.Position = points[5]
                part.Anchored = true
                part.CanCollide = false
                part.Parent = pointModel
            elseif points[4] then
                part = Instance.new("Part")
                part.FormFactor = Enum.FormFactor.Custom
                part.Size = Vector3.new(1, 1, 1)
                part.Transparency = 1
                part.Position = points[4]
                part.Anchored = true
                part.CanCollide = false
                part.Parent = pointModel
            elseif points[3] then
                part = Instance.new("Part")
                part.FormFactor = Enum.FormFactor.Custom
                part.Size = Vector3.new(1, 1, 1)
                part.Transparency = 1
                part.Position = points[3]
                part.Anchored = true
                part.CanCollide = false
                part.Parent = pointModel
            elseif points[2] then
                part = Instance.new("Part")
                part.FormFactor = Enum.FormFactor.Custom
                part.Size = Vector3.new(1, 1, 1)
                part.Transparency = 1
                part.Position = points[2]
                part.Anchored = true
                part.CanCollide = false
                part.Parent = pointModel
            elseif points[1] then
                part = Instance.new("Part")
                part.FormFactor = Enum.FormFactor.Custom
                part.Size = Vector3.new(1, 1, 1)
                part.Transparency = 1
                part.Position = points[1]
                part.Anchored = true
                part.CanCollide = false
                part.Parent = pointModel
            end

            if part then
                script.Parent.Humanoid:MoveTo(part.Position)
                script.Parent.Humanoid.MoveToFinished:Wait()
            end

            pointModel:ClearAllChildren()
        end
    end
end



Answer this question