Help with pathfind

I have a problem using pathfind. I’ve never used it, I’m just learning about it.

When my character is above 2.5 studs, the bot stops chasing, but I just programmed it to only jump

function IA.persuitPlayer(plr, yieldable)
	if plr:IsA("Player") then
		if IA.checkPlayerDistance(plr) == true then
			print("Can chase Player !")
			chasing = true

			while chasing == true and canChase == true do
			
				task.wait(0.1)
				local path = PathfindingService:CreatePath({["WaypointSpacing"] = 0.5})
				path:ComputeAsync(humanoidRootPart.Position, plr.Character.HumanoidRootPart.Position)

				for _, waypoint in pairs(path:GetWaypoints()) do
					if math.abs(waypoint.Position.Y-model.LeftFoot.Position.Y) > 2.5 then
						humanoid.Jump = true
					end
					humanoid:MoveTo(waypoint.Position)
				end		


			end
		else
			
			warn("Player Is Too Far.")
			
		end
		
	end
	
end

Video:

2 Likes

I don’t think there’s a need to calculate stuff and then make it jump. I’m very sure that there’s something that says when to jump.

if waypoint.Action == Enum.PathWaypointAction.Jump then
      humanoid.Jump = true
end
3 Likes

when you’re using

 PathfindingService:CreatePath()

are you changing the AgentCanJump parameter?

4 Likes

if I remove this check it simply goes against the part

1 Like

no, the only argument I sent was:

2 Likes

What about now?
char limitdddd

3 Likes

you also need to set “AgentCanJump” to true.

3 Likes

nah he shouldn’t, this is set to true by default

3 Likes

Can you try this to see if it would work?

3 Likes

In the documentation it says that the Default value is true, so I didn’t put it. but just in case I put it in now, and it didn’t work, it keeps stopping

image

2 Likes
function IA.persuitPlayer(plr, yieldable)
	if plr:IsA("Player") then
		if IA.checkPlayerDistance(plr) == true then
			print("Can chase Player !")
			chasing = true

			while chasing == true and canChase == true do

				task.wait(0.1)
				local path = PathfindingService:CreatePath({["WaypointSpacing"] = 0.5})
				path:ComputeAsync(humanoidRootPart.Position, plr.Character.HumanoidRootPart.Position)

				for _, waypoint in pairs(path:GetWaypoints()) do
					if waypoint.Action == Enum.PathWaypointAction.Jump then
						humanoid.Jump = true
					end
					humanoid:MoveTo(waypoint.Position)
				end		


			end
		else

			warn("Player Is Too Far.")

		end

	end

end
3 Likes

image

did not work

the waypoint doesn’t even reach the top of the part, it stops as soon as the player goes up

2 Likes

Maybe the wall is too high or something lol?

2 Likes

YES! HAHAHHA am so dumb

I can jump over it, but he can’t… I thought I could

ty man <3 also @Xantenius

image

4 Likes

Bruh, I thought that ComputeAsync would return nil if the path is impossible to complete.

2 Likes

trying to work out if there’s a workaround for this myself… hopefully can find something :stuck_out_tongue:

3 Likes

Hey dude, can you try this real quick? it’s worked for me, doesn’t matter the height

function IA.persuitPlayer(plr, yieldable)
	if plr:IsA("Player") then
		if IA.checkPlayerDistance(plr) == true then
			print("Can chase Player !")
			chasing = true

			while chasing == true and canChase == true do
			
				task.wait(0.1)
				local path = PathfindingService:CreatePath({["WaypointSpacing"] = 0.5})
				path:ComputeAsync(humanoidRootPart.Position, plr.Character.HumanoidRootPart.Position)

				for _, waypoint in pairs(path:GetWaypoints()) do
					humanoid:MoveTo(waypoint.Position)
					if waypoint.Action == Enum.PathWaypointAction.Jump then
						humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
						print('jumping')
					end
				end		


			end
		else
			
			warn("Player Is Too Far.")
			
		end
		
	end
	
end

maybe not the smoothest - but a start. Setting jump to true in your first example only allows the humanoid to jump. You gotta changed the HumanoidStateType to make it jump manually

3 Likes

humanoid.Jump = true is more effective, that code you said now made the bot fly lmao

2 Likes

Maybe just increase the JumpHeight or JumpPower of the bot? (In the humanoid)

1 Like

I’ll need to find a way to debounce it. So long as your jump height is 7.2, the first jump should be fine. But I know I need to debounce mine or it does go flying after the first jump lmao

1 Like