Zombie stuttering behind player?

Im making a zombie and when ever it is chasing a player and it gets close, it stutters behind the player. I know this is because of some issue where the server thinks your player is there vs where your player actually is on your client, is there any way to fix this issue? I have literally seen games from 10 years ago that don’t have this issue at all

A method for making hostile NPCs is to,

Have it path find towards the player when the zombie is not visible, such making a raycast between the player and zombie- if the zombie isnt visible to the player, the zombie PATH FINDS to the player, but when zombie is visible to the player, simply use the humanoid:MoveTo() to make the zombie run smoothly to, PREFERABLY, the front of the player.

1 Like

I’ll try this out and I’ll let you know if I have any issues, thanks

I’ve made it work but, any ideas on how to make it follow the “front” of the player? it appears that it still stutters behind me

local Players: Players = game:GetService("Players")
local Workspace: Workspace = game:GetService("Workspace")
local RunService: RunService = game:GetService("RunService")
local ServerScriptService: ServerScriptService = game:GetService("ServerScriptService")

local modules: Folder = ServerScriptService.Modules

local EntityController = require(modules.EntityController)
local SimplePath = require(modules.SimplePath)

local entity: Model = script.Parent
local entityHumanoid: Humanoid = entity.Humanoid
local humanoidRootPart: Part = entity.HumanoidRootPart

local ATTACK_RANGE: number = 3
local ATTACK_DAMAGE: number = 4
local ATTACK_COOLDOWN: number = .1

local attackCooldown: boolean = false

local Path = SimplePath.new(entity)
Path.Visualize = true

local raycastParams: RaycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.CollisionGroup = "Zombie"

local function attackPlayer(character: Model?)
	if attackCooldown then
		return
	end
	
	if character then
		local humanoid: Humanoid = character:FindFirstChildOfClass("Humanoid")
		
		if humanoid then
			humanoid:TakeDamage(ATTACK_DAMAGE)
			
			attackCooldown = true
			
			task.delay(ATTACK_COOLDOWN, function()
				attackCooldown = false
			end)
		end
	end
end

while true do
	local nearestCharacter: Model? = EntityController:getNearestCharacter(humanoidRootPart.Position)
	local nearestPlayer: Player = Players:GetPlayerFromCharacter(nearestCharacter)
	
	raycastParams.FilterDescendantsInstances = {script.Parent, nearestCharacter}
	local raycastResult: RaycastResult = Workspace:Raycast(humanoidRootPart.Position, nearestCharacter.PrimaryPart.Position - humanoidRootPart.Position, raycastParams)
	
	if not raycastResult then
		entityHumanoid:MoveTo(nearestCharacter.PrimaryPart.Position)
	else
		Path:Run(nearestCharacter.PrimaryPart.Position)
	end
	
	if (humanoidRootPart.Position - nearestCharacter.PrimaryPart.Position).Magnitude <= ATTACK_RANGE then
		attackPlayer(nearestCharacter)
	end
	
	humanoidRootPart:SetNetworkOwner(nil)
	
	task.wait(.1)
end

I think u have to get the lookvector of
nearestCharacter.PrimaryPart and add a small value

You need to pathfind when the raycast hits something that isn’t the target, not when it’s nil. If it filters the target, it may hit parts behind the target.

if not raycastResult or rayCastResult.Instance ~= nearsestCharacter.PrimaryPart then --//Hit wall.
	Path:Run(nearestCharacter.PrimaryPart.Position)
else --//No pathing required.
	entityHumanoid:MoveTo(nearestCharacter.PrimaryPart.Position)
end

If it is still stuttering, consider forcing the network owner of the NPC to the server with BasePart:SetNetworkOwner(nil). It would be ideal to have client-sided NPCs, but that might be a little complicated.

1 Like

Set the network owner to nil (the server) and it should stop the stuttering.

ZombiePart:SetNetworkOwner(nil) (do for all parts of the zombie)

These two links should give you info on it:

1 Like

I gave a solution to the same problem in this post: AI Pathfind Help - #12 by Lava_shield

1 Like