Basically, I'm trying to make an enemy thats just a little bit smarter than the usual "Follow Script." And for the most part, the pathfinding works. Except for the fact the AI has to go through the entire path before finding a new one. SO if the player moves, the enemy will first go to the players old position before calculating a new path to the players current position
This is the core pathfinding part of the script:
local tracking = false
local function pathTrack(target)
if tracking then return end
tracking = true
local path = pathFindingService:CreatePath()
path:ComputeAsync(root.Position, target.Position)
local wayPoints = path:GetWaypoints()
for _, waypoint in pairs(wayPoints) do
local p = Instance.new("Part")
p.Material = Enum.Material.Neon
p.Size = Vector3.new(0.6, 0.6, 0.6)
p.Position = waypoint.Position
p.Anchored = true
p.CanCollide = false
p.Parent = workspace
thanosHumanoid:MoveTo(waypoint.Position)
thanosHumanoid.MoveToFinished:Wait()
end
tracking = false
end
while wait(rTime) do
local target = findNearestTorso(root.Position)
if target ~= nil then
pathTrack(target)
end
end
if you need more info on the script, let me know
