So I have this slight issue, I’ve been using a tweaked version of the pathfinding found in the devforum + documentation
local Pathfinding = game:GetService("PathfindingService")
local Player = game:GetService("Players")
local RunService = game:GetService("RunService")
local wretch = script.Parent
local wretchHum = wretch.Humanoid
local whackSFX = wretch.UpperTorso.WhackSFX
local injurySFX = wretch.UpperTorso.InjurySFX
local animator = wretchHum:WaitForChild("Animator")
local RunAnim = script:WaitForChild("Run")
local Run = animator:LoadAnimation(RunAnim)
Run:Play()
local path = Pathfinding:CreatePath({
AgentHeight = 24;
AgentRadius = 24;
AgentCanJump = true;
AgentCanClimb = true;
Costs = {
Water = 100;
DangerZone = math.huge
}
})
local Character = script.Parent
local humanoid = Character:WaitForChild("Humanoid")
local waypoints
local nextWaypointIndex
local reachedConnection
local blockedConnection
local function findTarget()
local maxDistance = 600
local nearestTarget
for index, player in pairs(Player:GetPlayers()) do
if player.Character then
local target = player.Character
local distance = (Character.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude
if distance < maxDistance and target.Humanoid.Health > 0 then
nearestTarget = target
maxDistance = distance
end
if distance < 5 then
nearestTarget.Humanoid:TakeDamage(1000000000)
whackSFX.Playing = true
injurySFX.Playing = true
end
end
end
return nearestTarget
end
local function followPath(destination)
local success, errorMessage = pcall(function()
path:ComputeAsync(Character.PrimaryPart.Position, destination)
end)
if success and path.Status == Enum.PathStatus.Success then
waypoints = path:GetWaypoints()
blockedConnection = path.Blocked:Connect(function(blockedWaypointIndex)
if blockedWaypointIndex >= nextWaypointIndex then
blockedConnection:Disconnect()
followPath(destination)
end
end)
if not reachedConnection then
reachedConnection = humanoid.MoveToFinished:Connect(function(reached)
if reached and nextWaypointIndex < #waypoints then
nextWaypointIndex += 1
humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
else
reachedConnection:Disconnect()
blockedConnection:Disconnect()
end
end)
end
nextWaypointIndex = 2
humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
else
warn("Path not computed!", errorMessage)
end
end
while wait() do
local target = findTarget()
if target then
print(target.Name)
followPath(target.HumanoidRootPart.Position)
end
end
Now it works fine, except for some occassional jitters and the fact the ai completely ignores you after killing you,
but my biggest issue that he likes to shake in his spot at random spots, mainly near something like water or gaps that he can jump.
and a clip.
https://i.gyazo.com/6d2004d24de36e9948db69d4a6aaad79.mp4
update, it seems like he struggles around anything that is a ledge