Simply put, I spawn an AI and assign it a position, I print the waypoint positions yet for some reason the AI struggles to get to them, the moveto times out despite the AI being entirely able to get there. I am stumped at this point and have no idea what the issue could be, I thought it was the nav mesh but the nav mesh seems fine.
Here’s an image showing the path being computed, the AI is stuck where he stands though.
function AIService:PathfindToPosition(agent, endPosition)
if agent.activeTask then return end
print("Running pathfind")
local selected_agent = agent
local start_position = selected_agent.npc.PrimaryPart.Position
local agent_humanoid = selected_agent.npc:FindFirstChild("Humanoid")
local end_position = endPosition
agent.activeTask = true
local path = PathfindingService:CreatePath({
AgentCanJump = true,
AgentHeight = 5,
AgentRadius = 3,
Costs = {
}
})
local success, error_message = xpcall(function()
path:ComputeAsync(start_position, end_position + Vector3.new(8, 0, 0))
end, function()
warn("Path not computed")
return false
end)
local path_waypoints
local reached_connection
local blocked_connection
local next_index
if success and path.Status == Enum.PathStatus.Success then
path_waypoints = path:GetWaypoints()
for _, waypoint in ipairs (path_waypoints) do
local part = Instance.new("Part")
part.Size = Vector3.new(1,1,1)
part.Anchored = true
part.CanCollide = false
part.Parent = workspace
part.Position = waypoint.Position
part.Material = Enum.Material.Neon
end
blocked_connection = path.Blocked:Connect(function(blocked_index)
if blocked_index >= next_index then
blocked_connection:Disconnect()
agent.activeTask = false
end
end)
if not reached_connection then
reached_connection = agent_humanoid.MoveToFinished:Connect(function(reached_bool)
print(reached_bool)
if reached_bool and next_index < #path_waypoints then
next_index += 1
agent_humanoid:MoveTo(path_waypoints[next_index].Position)
else
reached_connection:Disconnect()
blocked_connection:Disconnect()
agent.activeTask = false
end
end)
end
next_index = 2
agent_humanoid:MoveTo(path_waypoints[next_index].Position)
end
end