Hello, While my npc is patroling, the pathfinding has no problem, nothing is stuttering or shaking, but when it’s chasing me, it starts to stutter, i was wondering on how to fix that, here’s the video: Watch Hit your Friend! 🥊 - Roblox Studio 2024-12-01 22-50-02 | Streamable
Chasing code:
function FriendsService:ComputeChasingPath(Player: Player, Rig: Model)
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local RigHumanoid = Rig:WaitForChild("Humanoid")
RunService.Stepped:Connect(function()
if not Rig:GetAttribute("ChasingPlayer") then return end
local StartPosition = Rig.PrimaryPart.Position
local TargetPosition = Character.PrimaryPart.Position
local Success, ErrorMessage = self:SafeComputePath(StartPosition, TargetPosition)
if Success then
if self.Path.Status == Enum.PathStatus.Success then
local Waypoints = self.Path:GetWaypoints()
local Distance = (
Rig.PrimaryPart.Position - Character.PrimaryPart.Position
).Magnitude
if Distance < Constants["ATTACK_DISTANCE"] and Humanoid.Health > 0 then
Humanoid:TakeDamage(Constants["CHASING_DAMAGE"])
Rig:SetAttribute("ChasingPlayer", false)
Player:SetAttribute("Chased", false)
RigHumanoid.WalkSpeed = Constants["REGULAR_NPC_WALKSPEED"]
else
RigHumanoid:MoveTo(Character.PrimaryPart.Position, Character.PrimaryPart)
end
for _, Waypoint in Waypoints do
if workspace:GetAttribute("DEBUG") then
local Part = Instance.new("Part")
Part.Position = Waypoint.Position
Part.Color = Color3.fromRGB(255, 255, 0)
Part.Material = Enum.Material.Neon
Part.Shape = Enum.PartType.Ball
Part.Size = Vector3.one * 0.5
Part.CanCollide = false
Part.Anchored = true
Part.Parent = workspace.Map.Trash
task.delay(0.5, function()
Part:Destroy()
end)
end
if Waypoint.Action == Enum.PathWaypointAction.Jump then
RigHumanoid.Jump = true
end
RigHumanoid:MoveTo(Waypoint.Position, Character.PrimaryPart)
end
else
-- Do nothing if path is not computed, it'll resolve itself
return
end
else
warn(`Cound't compute Chasing Path, error: {ErrorMessage}`)
return
end
end)
end
Agent parameters
Path = PathfindingService:CreatePath({
WaypointSpacing = 100,
AgentCanClimb = true,
AgentCanJump = false,
PathSettings = {
["SupportPartialPath"] = true
}
}),