Help with simplepath npc (jitters alot)

why does it jitter all like that (i use simplepath module)
pls awnser me, i have been searching for a solution last month and this month (fun fact it did not help at all)

pls. if additional info is needed please inform me of it… im legit so tired of this one thing its been bothering me since the start of time itself and i might not awnser immediately but please dont be hesitant to awnser i would literally accept any help just plzzzzz i hate this bug so muuuch

--((Services))
local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService('Players')
local PathfindingService = game:GetService("PathfindingService")

--((Variables))
local SimplePath = require(ServerStorage.SimplePath)
local NPC = script.Parent
local Animator = NPC.Humanoid:FindFirstChild("Animator")
local Animation = ServerStorage.Anims.Attack
local AnimationLoaded = Animator:LoadAnimation(Animation)
local WooshSFX = NPC.HumanoidRootPart.Woosh

local Extraspeed = script.Parent:GetAttribute("AttackSlowdown")

--((Attack Function))
local function AttackFX()
	WooshSFX:Play()
	AnimationLoaded:Play()
end

for index, NPCpart in pairs(NPC:GetDescendants()) do
	if NPCpart:IsA("MeshPart") or NPCpart:IsA("BasePart") then
		NPCpart:SetNetworkOwner(nil)
	end
end

local AgentParams = {
	AgentRadius = 2,
	AgentHeight = 5,
	AgentCanJump = true,
	AgentCanClimb = false,
	WaypointSpacing = 4
}

--((StartAI Function))
local function StartAI()
	local NearestPLR, NearestDist, NearestAttackDist, Damage = nil, nil, nil, nil
	local path = SimplePath.new(NPC, AgentParams)
	--((Path Variables))
	path.Visualize = true

	while wait() do
		if NPC.Humanoid.Health > 0 then
		
		NearestPLR, NearestDist, NearestAttackDist, Damage = nil, NPC:GetAttribute("SearchRange"), NPC:GetAttribute("AttackDistance"), NPC:GetAttribute("Damage")


				for _, plr in ipairs(workspace:GetChildren()) do
					if plr ~= nil then
						if plr:FindFirstChild("IsPlayer") or plr:FindFirstChild("IsCore") then
							local dist = (NPC.PrimaryPart.Position - plr.PrimaryPart.Position).Magnitude		
							
							if dist < NearestDist then

								NearestPLR = plr
								NearestDist = dist

								if dist < NearestAttackDist then
									AttackFX()
									NPC.Humanoid.WalkSpeed = NPC.Humanoid.WalkSpeed - Extraspeed
									task.wait(0.4)
									local Coroutine = coroutine.wrap(function()
										local dist2 = (NPC.PrimaryPart.Position - plr.PrimaryPart.Position).Magnitude		
										if dist2 < NearestAttackDist then
											local hum = plr:FindFirstChild("Humanoid")
											hum:TakeDamage(Damage)
											end
											NPC.Humanoid.WalkSpeed = NPC.Humanoid.WalkSpeed + Extraspeed
											task.wait(1.5)
										end)
										Coroutine()
									end	
								end
							end	
						end
					end
				end

			if NearestPLR ~= nil then
				
				
				
				path.Blocked:Connect(function()
					if NearestPLR then
						SimplePath:Run(NearestPLR.PrimaryPart)
					end
				end)

				path.WaypointReached:Connect(function()
					if NearestPLR then
						path:Run(NearestPLR.PrimaryPart.Position)
					end
				end)

				if NearestPLR then
					path:Run(NearestPLR.PrimaryPart.Position)
				end
				
				NPC.Humanoid.Died:Connect(function()
					SimplePath:Stop()
				end)
			end
		end
	end

StartAI()

what why :frowning: I’ve been dealing with a similar issue and have been trying a lot of methods. Like the pathfinding is useful but then I also want the npc to like strafe. I’m just wondering how to make like ranged NPCs and melee NPCs.

2 Likes

make a event for the ranged npc to fire a bullet (example) and just fire the event whenever pretty simple samething with the melee part just use magnitude if you want a easy way of doing melee and so on (its quite efficient actually but not when you want changeable hitboxes)

1 Like

How do you think I could do a state machine with this? To go through certain behaviors, so it’d be easy to go from Idle or like Travelling to Combat.

Ex:
–Defaults–
Idle
WanderRadius
WanderWaypoints
–Active–
Melee Combat
Ranged Combat
Travelling (Point A → Point B)

2 Likes

What rig are you using for the zombie? Could you elaborate on it?

I’ve had this same issue due my rig being scaled improperly.
Is the model Scale set to 1, did you do any rescaling, etc.?

Also, does the same script do this with all characters? That is, a random dummy character from the Toolbox for example.

1 Like

alright so from what i see after i tried this method all that happened was nothing changed

1 Like

attributes? like attributes being an artificial state thing?

also i dont think you should be asking for these stuff in a topic about where i need help.
if you need help why not make your own topic

1 Like

I’d say it’s simply just calling it too much. And the parameters are probably over-specific. If possible, switch the movement function to :Move() and make it call less. It has too many way points.

2 Likes

wdym by switching the movement function to :Move()

1 Like

you can like find the magnitude and direction of a target and then call move on a humanoid every heartbeat my bad for reply above

1 Like

ik but im just confused on what he means by switching too that function

1 Like

ive realised what you’ve meant and, it is not ideal and hasn’t fixed it
why would you use :move() anyways