Is there a better way in updating an NPC’s path to follow the player? Currently, whenever the player moves the NPC is unable to catch up to the player even though its humanoid walkspeed had been set to 50.
https://gyazo.com/b0a971b7714c76c0ecc8685de82997b2
Module script
function NPC_AIPathfinding.ChasePlayer(Guard, player)
local PathfindingService = game:GetService("PathfindingService")
while wait(0.2) do
if Guard.Humanoid.Chasing.Value == false then
break
end
local StartPosition = Guard.HumanoidRootPart.Position -- Move NPC towards player previous position
local EndPosition = player.Character.HumanoidRootPart.Position
local Path = PathfindingService:CreatePath()
Path:ComputeAsync(StartPosition, EndPosition)
local waypoints = Path:GetWaypoints()
for _, waypoint in pairs(waypoints) do -- Loop through waypoints
Guard.Humanoid:MoveTo(waypoint.Position)
end
end
end