How to make AI pathfind in front of a part instead of trying to jump on top?

I am trying to make a robot with pathfinding AI go to a part and not try to jump on top of it. Any simple way to do so?

Here’s the code for when the robot goes to a target.

local Humanoid = script.Parent.Humanoid
local Root = script.Parent:FindFirstChild("HumanoidRootPart")
local parts = workspace:GetPartBoundsInRadius(script.Parent.PrimaryPart.Position,100)-- A model in workspace with all spawns.
local Closest -- This will be set as the closest spawn to the player
local parent = script.Parent
local PlayerPosition = parent.PrimaryPart.Position
local calcpath = PathfindingService:CreatePath()
function calculate(thing)
	warn(thing.Name.." is the target.")
	calcpath:ComputeAsync(script.Parent.HumanoidRootPart.Position, thing.Position)
	--calcpath:ComputeAsync(script.Parent.HumanoidRootPart.Position, workspace.Target.Position)
	script.Parent.Target.Value = thing.Name

	warn("Calculated!")
	if calcpath.Status == Enum.PathStatus.Success then
		local ways = calcpath:GetWaypoints()
		warn("Where to go?")
	for i, point in ipairs(ways) do
		warn("I know where to go, can I get there?")
		Humanoid:MoveTo(point.Position)
		print("Go!")
		local pathview = Instance.new("Part")
		pathview.Name = "PathfindTrack"
		pathview.Size = Vector3.new(1,0,1)
		pathview.BrickColor = BrickColor.new("Electric blue")
		pathview.Parent = workspace
		pathview.Position = point.Position
		pathview.Material = Enum.Material.Neon
		pathview.Anchored = true
		pathview.CanCollide = false
		print("run")
		if script.Parent.Wheel["small motor loop"].Playing == false then
			script.Parent.Wheel["small motor loop"].Playing = true
		end
		if point.Action == Enum.PathWaypointAction.Jump then
       calcpath = nil
		end

		Humanoid.MoveToFinished:Wait()
		script.Parent.Wheel["small motor loop"].Playing = false
		--script.Parent.HumanoidRootPart.Orientation = CFrame.lookAt(thing.Position, thing.Orientation)
		end
	else
		error("Uh oh, I couldn't calculate a path!")
	end
end

Good luck working with my spaghetti code.
Also, my robot, in terms of design, cannot jump.

1 Like

You can set parameters when creating a path, one of the parameters is AgentCanJump which you can set to false.
You can find out more about the parameters and how to set them here:

1 Like

it just wont calculate a path now

local calcpath = PathfindingService:CreatePath({AgentCanJump = false})
1 Like

There are a number of reasons why a path isn’t being created, a common one is because there is something blocking the way to the end position. Could be the path is too narrow. If it was creating the path ok before you set the AgentCanJump then check a route is possible around the area where the jumps where happening.

1 Like

image_2022-07-16_095746639

1 Like

The simple method would be to break the loop before the final MoveTo. So your code would look like:

for i, point in ipairs(ways) do
	if i == #ways then return end
	warn("I know where to go, can I get there?")
	..-- the rest of your code
1 Like

Now here’s the problem. The AI will not calculate a path if there is no ramp to the top of the part.

OK. A solution would be to get the vector to the part, then calculate a distance n studs (part size dependent) before it and base your path destination on that calculated position.

1 Like

tried doing raycasts from the part instead, it works

1 Like