Creature Pathfinding Jitters And Slows Down Near Player

Hello! I’m Making A Horror Game With Multiple Creatures In It, However Whenever The Player Goes Near The Creature Its Pathfinding Gets All Jittery And Even Stops For Long Periods Of Time. I Tried To See What Would Happen If I Put A Rig In Front Of It, But It Worked Perfectly. Can Someone Help Explain What’s Going On And How I Can Fix It.

My Code:

local pathFindingService = game:GetService("PathfindingService")
local creatureSelf = script.Parent
local selfHum =  creatureSelf.Humanoid

local pathNodeTable = workspace.MineshaftNodes.Nodes:GetChildren()

while true do
	wait()
	local pathPoint = workspace.MineshaftNodes.Nodes[math.random(1, #pathNodeTable)]
	--local pathPoint = workspace.MineshaftNodes.Nodes[2]
	if pathPoint.Checked.Value ~= true then

		local path = pathFindingService:CreatePath({
			Costs = {
				DangerZone = math.huge,
				YabbaDabbaDoo = 2,
				CheckPoint = 1
			}
		})

		path:ComputeAsync(creatureSelf.HumanoidRootPart.Position, pathPoint.Position)

		for i, waypoint in pairs(path:GetWaypoints()) do
			--print(waypoint.Position)
			selfHum:MoveTo(waypoint.Position)
			selfHum.MoveToFinished:Wait()
		end
		pathPoint.Checked.Value = true
		pathPoint.Parent.Parent.TotalChecked.Value = pathPoint.Parent.Parent.TotalChecked.Value + 1
		print("Path Complete")
		wait(5)
	else
		print("Already Checked")
		if workspace.MineshaftNodes.TotalChecked.Value == #pathNodeTable then
			for count, v in pairs(pathNodeTable) do
				v.Checked.Value = false
			end
			workspace.MineshaftNodes.TotalChecked.Value = 0
		end
	end
end

2 Likes

I’ve been having similar problems.

I’m not sure about the jittering as of right now.

However, as for the creature slowing down near the player, you’re going to want to set the network ownership of the creature to the server. *
A parts network owner is what controls its physics.

Essentially, loop through all the descendants of the creature model, and if its a basePart / unionOperation / meshPart, you can run the following method.

part:SetNetworkOwner(nil)

(by setting it to nil, you’re giving the server control)

This might not be 100% optimal, because this thing I read on the documentation is making me uneasy*

“can result in jittery physics for clients”
That being said, “gameplay-critical objects that the client should not be able to manipulate” perfectly describes the creature.

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.