How can I get rid of this delay and make it smooth?

What do I want to achieve? Smooth turning like this:
https://www.youtube.com/watch?v=ckA4fVkAjIA&t=1678s (From 32:05 to end of vid)

What is the issue? Turning is not smooth

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Here is the script:

local Players = game:GetService("Players")
local PathfindingService = game:GetService("PathfindingService")

local zombieDamage = 10

local rig = script.Parent

local function checkForCharacter(character)
	local rayOrigin = rig:FindFirstChild("HumanoidRootPart").Position
	local rayDirection = (character.HumanoidRootPart.Position - rayOrigin).Unit * 40
	
	local raycastResult = workspace:Raycast(rayOrigin, rayDirection, RaycastParams.new())

	if raycastResult then
		local raycastInstance = raycastResult.Instance
		if raycastInstance:IsDescendantOf(character) then
			return true
		end
	else
		return false
	end
end

local function findNearestPlayer()
	local players = Players:GetPlayers()
	local nearestPlayer = nil
	local maxDistance = 40
	
	for _, player in pairs(players) do
		if player.Character ~= nil then
			local targetCharacter = player.Character
			local distance = (rig.HumanoidRootPart.Position - targetCharacter.HumanoidRootPart.Position).Magnitude
			
			if distance < maxDistance and checkForCharacter(targetCharacter) then
				nearestPlayer = targetCharacter
				maxDistance = distance
			end
		end
	end
	return nearestPlayer
end

local function attack(character)
	local distance = (rig.HumanoidRootPart.Position - character.HumanoidRootPart.Position).Magnitude

	if distance > 5 then
		rig.Humanoid:MoveTo(character.HumanoidRootPart.Position)
	else
		character.Humanoid.Health -= zombieDamage
	end
end

local function calculatePath(destination)
	local agentParams = {
		["AgentHeight"] = 5,
		["AgentRadius"] = 4,
		["AgentCanJump"] = false
	}
	
	local path = PathfindingService:CreatePath(agentParams)
	path:ComputeAsync(rig.HumanoidRootPart.Position, destination)
	return path
end

local function walkToDestination(destination)
	local path = calculatePath(destination)
	
	if path.Status == Enum.PathStatus.Success then
		for _, waypoint in pairs(path:GetWaypoints()) do
			local nearestPlayer = findNearestPlayer()
			if nearestPlayer then
				attack(nearestPlayer)
				break
			else
				rig.Humanoid:MoveTo(waypoint.Position)
				rig.Humanoid.MoveToFinished:Wait()
			end
		end
	else
		rig.Humanoid:MoveTo(destination - (rig.HumanoidRootPart.CFrame.LookVector * 10))
	end
end

local function patrol()
	local waypoints = workspace.Waypoints:GetChildren()
	local randomNumber = math.random(1, #waypoints)
	
	walkToDestination(waypoints[randomNumber].Position)
end

while task.wait(.3) do
	patrol()
	if rig.Humanoid.Health == 0 then
		rig:Destroy()
	end
end
``

Also will be responde tomorrow.

Thanks for the Help!

The rigs pathing seems to be updating repeatedly, meaning it’s just turning because the function was called again and it’s changing it’s direction very often so it’s a small change

If you were to have a singular rig, it would probably be fine, but if you want lots of zombies it’s gonna tank performance, you need a different method or dealing with the enemies just not turning smoothly

So how could i achieve this? And yes there would be more Zombies

First thing that comes to mind is an IKControl set to Enum.IKControlType.LookAt whose target is the player’s primary part

I think you may get some silly interactions when zombies chase players on a different altitude

Also, only set the IK’s target to the player if they can see the player, otherwise you’ll just have zombies facing walls while walking towards people

1 Like

Where would i put the IKcontrol? Would it be the HumanoidRootPart?

You could try tweening it client sided. Maybe make a copy of the dummy rig or use unreliable remote events to update its position and rotation. It really depends on how many mobs youre gonna have because both of these methods are pretty taxing really quickly. The IK Controls could work as well either serverside or clientside. But, the rule of thumb is if you want to make visuals smooth you should render it on the client.

I could use this method since i would have a lot of Zombies but Tweening wouldn’t let me animate them right?

Good question. Not sure if tweening overrides animations myself. Maybe if you tween just the rotation you could still animate, not sure though.

It wouldn’t override i belive, and it wont look right since the script doesnt think its walking

The script would be Animate but a Server script in the zombie

Yeah the chain just has to affect the humanoid root part since everything should follow

If you don’t mind them doing the walking animation even while standing still you can just play the animation when you spawn them in and forget about it (you still need something to make them play the attack animation though)

If you’re gonna have more than 30 zombies than that’s gonna raise your network. You’re most likely gonna need to make non humanoid zombies and render them on the client using tween.

But if you do choose to have humanoids then the best thing you can do it disable as much humanoid states.