I’ve been trying to replicate Baldi’s AI from Baldi’s Basics Classic for quite some time now, but still couldn’t get down to the core of this singular issue
I set up pathways for the AI to use in order to move to the selected wander point, but it just seems to completely ignore that.
For context, I want Baldimore here to move on the blue lines and nowhere else. I did see on another Forum post that it may be related to the NPC skipping straight to the last waypoint of the path, but that doesn’t seem to be the case since Baldi does follow correctly up to a point, then just zooms straight to the end
Additionately, he seems to be ignoring some wander points and only moving between two specific ones, probably because math.random isn’t the ideal choice for randomness but I believe something else may also be the underlying cause
What did I do wrong?
Here’s the code. You can probably tell it’s unfinished.
local Baldi = workspace.Baldi
local AIFolder = workspace.AI
local WanderPaths = AIFolder.WanderPaths:GetChildren()
local WanderPoints = AIFolder.WanderPoints:GetChildren()
local LastWanderPoint = nil
local PathServ = game:GetService("PathfindingService")
local SlapRate = 3
local State = "Wander"
local function Calculate(Path, WanderPoint)
Path:ComputeAsync(Baldi.HumanoidRootPart.Position, WanderPoint.Position)
end
local function AILoop()
if State == "Wander" then
local Path = PathServ:CreatePath({
AgentRadius = 0.4,
AgentCanClimb = false,
Costs = {
WanderPaths = 1
}
})
local WanderPoint = WanderPoints[math.random(1, #WanderPoints)]
if WanderPoint == LastWanderPoint or WanderPoint:IsA("Script") or not WanderPoint then
repeat
local WanderPoint = WanderPoints[math.random(1, #WanderPoints)]
task.wait()
until WanderPoint ~= LastWanderPoint and WanderPoint:IsA("BasePart")
end
LastWanderPoint = WanderPoint
local Success
local Attempts = 0
repeat
Attempts = Attempts + 1
local Success, ErrorMessage = pcall(Calculate, Path, WanderPoint)
if not Success then
warn("Attempting to recalculate trajectory")
warn(ErrorMessage)
end
until Success or Attempts >= 11
for i,v in pairs(Path:GetWaypoints()) do
local waypoint = Path:GetWaypoints()[i]
Baldi.Humanoid:MoveTo(waypoint.Position)
Baldi.Humanoid.MoveToFinished:Wait()
end
end
end
task.wait(4)
print("Started!")
while true do
AILoop()
end
