Hello there,
So I’ve been working on this AI for a little while now but it keeps bumping into walls at certain points as shown in the video down below:
I’ve checked multiple different posts & tried all of it but it still ain’t working.
Here’s my code:
local pathfindingService = game:GetService("PathfindingService")
local players = game:GetService("Players")
local monster = workspace:WaitForChild("Monster")
local primary = monster.PrimaryPart
local humanoid = monster:WaitForChild("Humanoid")
local waypoints = workspace:WaitForChild("Points")
local maxFindingRange = 30
local maxKillingRange = 5
local chasingSpeed = 17
local regularSpeed = 12
local prevPoint = nil
primary:SetNetworkOwner(nil)
task.wait(2)
local function GetPath()
local path = pathfindingService:CreatePath{
['AgentRadius'] = 2,
['AgentHeight'] = 5,
['AgentCanJump'] = false,
['AgentCanClimb'] = false,
['WaypointSpacing'] = 4,
['Costs'] = {
Water = math.huge,
}
}
return path
end
local function WalkTo(dest: Vector3, isPoint: boolean)
local path: Path = GetPath()
path:ComputeAsync(primary.Position, dest)
local points = path:GetWaypoints()
if not (points) then return end
for _, point in pairs(points) do
local part = Instance.new("Part", workspace)
part.Position = point.Position
part.Color = Color3.fromRGB(255, 255, 15)
part.Shape = "Ball"
part.Anchored = true
part.CanCollide = false
part.Size = Vector3.new(2, 2, 2)
game:GetService("Debris"):addItem(part, 1)
humanoid:MoveTo(point.Position)
humanoid.MoveToFinished:Wait()
print('reached waypoint')
end
end
local function GetRandomWaypoint()
local int = 1
if (prevPoint ~= nil) then
int = tonumber(prevPoint.Name) + 1
end
if (int > #waypoints:GetChildren()) then
int = 1
end
local point = waypoints:FindFirstChild(tostring(int))
if (point) then
prevPoint = point
return point
else
point = waypoints:FindFirstChild('1')
end
end
local function Patrol()
local point = GetRandomWaypoint()
print('Found point: ' .. point.Name)
WalkTo(point.Position, true)
end
while task.wait() do
print('Patrolling')
Patrol()
end
No errors are displayed either,