Help with Pathfinding freaking out

Hey there!

I’m making a brand new AI, and the AI right now freaks out if it jumps. What I’m trying to do is make it jump nice and perfectly while updating instantaneously. Now, as you can see from the videos below, the one where it makes it perfectly has a wait time of 15 seconds, I don’t want that. I want it to update every frame basically, so it can run after the player.

The clip where the AI FAILS, is the one where the wait time is set to each frame. Whenever it jumps, it freaks out.

If someone could help me solve this and combine the best of both worlds, that’d be amazing! Thank you.



-- More code above here


--// Updates the pathfinding
local function update(targetModel)
	local success, errorMsg = pcall(function()
		Path:ComputeAsync(Killer.HumanoidRootPart.Position, targetModel.HumanoidRootPart.Position)
	end)
	
	if not success then
		warn("Path computation failed: ", errorMsg)
		return
	end
	
	if Path.Status == Enum.PathStatus.NoPath then
		NoPathMoveTo(targetModel.HumanoidRootPart.Position)
	end
	local Waypoints = Path:GetWaypoints()
	table.remove(Waypoints, 1)
	
	coroutine.wrap(followPath)(Waypoints)
	if Settings.DebugWithPoints == true then
		for _, waypoint in ipairs(Waypoints) do
			local point = Instance.new('Part')
			point.Anchored = true
			point.Size = Vector3.new(1, 1, 1)
			point.Position = waypoint.Position
			point.CanCollide = false
			point.Parent = Killer.DebugStorage
			Debris:AddItem(point, 0.1)
		end
	end
end



--// Follows the pathfinding
function followPath(waypoints)
	ActiveCoroutine = coroutine.running()
	for _, waypoint in ipairs(waypoints) do
		if ActiveCoroutine ~= coroutine.running() then
			return
		end
		
		if waypoint.Action == Enum.PathWaypointAction.Jump then
			Humanoid:MoveTo(waypoint.Position)
			Humanoid.Jump = true
		else
			Humanoid:MoveTo(waypoint.Position)
		end
		Humanoid.MoveToFinished:Wait()
		if Settings.DebugWithPoints then
			Killer.DebugStorage:ClearAllChildren()
		end
	end
end



while true do
	update(workspace.Hacker)
	task.wait() -- what ever it is. 15 seconds compared to 0.01 seconds
end
2 Likes

This is because when it’s in air it finds a shorter path to the dummy/rig even tho that path doesn’t work it’ll try to “fly” there.

1 Like

Is there a solution to fix this? And make it stay on the same path unless it needs to go down?

1 Like

What can i do to prevent it, or at least change it to make it best of both worlds?

I haven’t really looked deep into pathfindingservice myself but maybe you can make a raycast that detects the next part that it should go to, like you had shown in the video it was twitching upon reaching the truss. You can maybe raycast detect the truss and then make it the new goal and if it’s reached then continue to the original goal.

Thing is, I have no idea how to solve that issue. I was wondering if anyone else would know and help me out with it.

I’m not well equipped to know how to fix that sadly, if I find a solution I’ll let you know.

Alright, I’ll be constantly checking this Post to see if ANYONE has ANY answers.

1 Like

I fixed the issue with it not being able to jump, but there’s ONE LAST issue I can’t and don’t know how to fix. The pathfinding stops when it sees a player and directly runs towards the player, making it less performance-costly, but if I remove it, it works perfectly… problem is that it becomes laggy. So I need it when it sees a player to just move to them… but I also want it to not just walk off the edge. I wonder if there is a way to make it pathfind and check if there is a safeway to make it to the player without falling or something.