I am developing a game that plays like piggy, and I’ve coded a custom bot, but it gets stuck all the time, on walls, it can’t go down certain hallways that are certainly wide enough for it, and it is altogether just quite buggy. I’ve checked where it gets stuck, and it should be able to pathfind through there, but instead it just does what it does when a paths success is false
– createPath function
local function getPath(target)
local pathParams = {
["AgentHight"] = 9,
["AgentRadius"] = 3.5,
["AgentCanJump"] = true
}
local path = pathfindingservice:CreatePath(pathParams)
path:ComputeAsync(sunny.HumanoidRootPart.Position, target.HumanoidRootPart.Position)
return path
end
– walkTo function
local function walkTo(target)
local path = getPath(target)
if path.Status == Enum.PathStatus.Success then
for index, waypoint in pairs(path:GetWaypoints()) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
if target and target.Humanoid.Health > 0 then
if CanSeeTarget(target) then
humanoid:MoveTo(target.HumanoidRootPart.Position)
sunny.Eyes.Color = sunny.GlowingEye.Color
sunny.Eyes.Material = Enum.Material.Neon
break
end
humanoid:MoveTo(waypoint.Position)
sunny.Eyes.Material = eyeMaterial
sunny.Eyes.Color = eyeColour
humanoid.MoveToFinished:Wait()
else
sunny.Eyes.Material = eyeMaterial
sunny.Eyes.Color = eyeColour
humanoid:MoveTo(sunny.HumanoidRootPart.Position - Vector3.new(math.random(-5,5), 0, math.random(-5,5)))
humanoid.MoveToFinished:Wait()
end
end
else
humanoid:MoveTo((sunny.HumanoidRootPart.Position - Vector3.new(0, 0, -3)) - (sunny.HumanoidRootPart.CFrame.LookVector * 2))
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
wait(0.1)
end
end
local function patrol()
local target = findTarget()
if target then
walkTo(target)
target = findTarget()
end
end
while wait(0.1) do
patrol()
end