Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

PathfindingService not recognizing jumps?

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



1 answer

✓ Accepted answer

Okay so I figured it out so ComputeRawPathAsync() function is deprecated You can read more on that here https://wiki.roblox.com/index.php?title=API:Class/PathfindingService/ComputeRawPathAsync

And I replaced GetPointCoordinates() function with GetWaypoints() Read more on that https://wiki.roblox.com/index.php?title=API:Class/Path/GetWaypoints

I removed some code. It not perfect but works.

wait(3)

local localCharacter = script.Parent
local start

--This check what type of rig you are using R15 or R16
if localCharacter.Humanoid.RigType == Enum.HumanoidRigType.R15 then
	start = localCharacter.UpperTorso
else
	start = localCharacter.Torso
end	

local pathfindService = game:GetService("PathfindingService")
local PlayerService = game:GetService("Players")

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:FindPathAsync(start.Position, chosenPlayer.Character.LowerTorso.Position, 10000)
            local points = path:GetWaypoints()
            for a = 1,#points do
                if points[a].Action == Enum.PathWaypointAction.Jump then
                    script.Parent.Humanoid.Jump = true
                    script.Parent.Humanoid:MoveTo(points[a+1].Position)
					wait(0.1)
                else
                    script.Parent.Humanoid:MoveTo(points[a].Position)
                    wait(0.1)
                end
            end

        end
    end
end

5 comments

0

Well, I already knew it was deprecated, but I wanted to use it since the wiki made it a lot more confusing than it needed to be. I'll try this out.

0

It worked, thanks!

0

Actually, it doesn't work totally as expected. It still won't jump from block to block

0

You can try to figure it out from there.

0

I was thinking now is if one of the points is below the zombie position it will jump.you can check the each position with points variable it stores all the points.

This discussion is preserved as it was. New answers, comments, and votes are closed.