Hi, I’m making AI pathfinding but I don’t know how to make NPC jump over an obstacle while following path. I just tried to check if path.Status == Enum.PathWaypointAction.Jump and then jump. But it didn’t worked. Here is my code:
local Rig = script.Parent
local Humanoid = Rig.Humanoid
local BasePart = Rig.HumanoidRootPart
local PlayerService = game:GetService("Players")
local PathFindingService = game:GetService("PathfindingService")
Rig.PrimaryPart:SetNetworkOwner(nil)
function createPath(destination)
local pathParams = {
AgentRadius = 4,
AgentHeight = 6.5,
AgentCanJump = true
}
local path = PathFindingService:CreatePath()
path:ComputeAsync(BasePart.Position, destination.Position)
for i, w in pairs(workspace.waypoints:GetChildren()) do
w:Destroy()
end
local waypoints = path:GetWaypoints()
for i, w in pairs(waypoints) do
local waypoint = Instance.new("Part")
waypoint.Name = tostring(table.find(waypoints,w))
waypoint.Position = w.Position
waypoint.CanCollide = false
waypoint.Parent = workspace.waypoints
waypoint.Shape = "Ball"
waypoint.Size = Vector3.new(1, 1, 1)
waypoint.Anchored = true
end
return path
end
function walkTo(destination)
local path = createPath(destination)
local waypoints = path:GetWaypoints()
if path.Status == Enum.PathWaypointAction.Jump then
Humanoid.Jump = true
end
if waypoints[2] then
Humanoid:MoveTo(waypoints[2].Position)
end
end
while true do
local Players = PlayerService:GetPlayers()
if Players[1] then
local character = Players[1].Character or Players[1].CharacterAdded:Wait()
if character then
local target = Players[1].Character
walkTo(target.HumanoidRootPart)
end
end
wait(0.0001)
end