Hello the, my fellas,
I am trying to make a chasing AI bot using my own script, I used the PathfindingService feature for the first time. I got confuse, why did it still trying to go trought wall? I already use path params but still didn’t work. Hope you guys can help
AI:
local PathfindingService = game:GetService("PathfindingService")
local CollectionService = game:GetService("CollectionService")
local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Modules = ReplicatedStorage:WaitForChild("Modules")
local killer = script.Parent
local rootPart = killer.HumanoidRootPart
local humanoid = killer.Humanoid
for index, part in pairs(killer:GetChildren()) do
if part:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(part, "KillerBot")
end
end
local function searchForPath(object)
local pathParams = {
["AgentHeight"] = 10,
["AgentRadius"] = 5,
["AgentCanJump"] = true
}
local path = PathfindingService:CreatePath(pathParams)
path:ComputeAsync(rootPart.Position, object.Position)
return path, path:GetWaypoints()
end
local function getPlayer()
local players = Players:GetPlayers()
local maxDistance = 100
local nearestTarget
local plr
local char
for index, player in pairs(players) do
plr = player
if player.Character then
char = player.Character
local target = char
local distance = (rootPart.Position - target.HumanoidRootPart.Position).magnitude
if distance > maxDistance then
maxDistance = distance
nearestTarget = target
end
else
char = nil
end
end
return nearestTarget, plr, char
end
local function randomMovement()
local number = 2
local randomNumber = math.random(1, number)
local destination = Vector3.new(randomNumber, 0, randomNumber)
humanoid:MoveTo(destination)
end
local function patrolMovement()
local target, player, character = getPlayer()
local path, waypoints
local characterStatus
if character ~= nil then
path, waypoints = searchForPath(character.HumanoidRootPart)
characterStatus = true
else
path, waypoints = searchForPath(rootPart)
characterStatus = false
end
if path.Status == Enum.PathStatus.Success then
for index, waypoint in pairs(waypoints) do
if characterStatus == true then
humanoid:MoveTo(character.HumanoidRootPart.Position)
else
randomMovement()
end
end
else
randomMovement()
end
end
while wait(0) do
patrolMovement()
end

