NPC Stutter-stepping when CFrame is modified

  1. What do you want to achieve?
    Want NPCs to track their target while moving around
  2. What is the issue?
    It works, but every time the HRPs CFrame gets adjusted, it takes a few milliseconds, and during that time the NPC doesnt move. When the CFrame is set, it rubberbands farther down along its MoveTo() path…
  3. **What solutions have you tried so far?

I tried using AlignOrientation instead of adjusting the CFrame. This worked, but also didnt. It caused a bug where sometimes the NPC would get yeeted off into space.

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 movement code, its a function that gets called only if the isPathing variable is false.

--Temporary function while pathfindingService gets fixed
function BotClass:SimpleMoveTo(dest)
	self.isPathing = true
	--checks if the movement should be interrupted, or is finished
	task.spawn(function()
		while self.isPathing and not self.isDead do
			task.wait(0.5)
			--we should track a target if we have one
			if not self.interruptMove then
				if self.currentTarget == nil then
					--dont need to track target
					self.botModel.Humanoid.AutoRotate = true
					self.botModel.Humanoid:MoveTo(dest) --go
				else
					--need to track target
					self.botModel.Humanoid.AutoRotate = false
					self.botModel.HumanoidRootPart.CFrame = CFrame.lookAt(self.botModel.HumanoidRootPart.Position,self.currentTarget.PrimaryPart.Position)
					self.botModel.Humanoid:MoveTo(dest) --go
				end
			else
				self.botModel.Humanoid:Move(Vector3.new(0,0,0)) --stop
			end
			--
			if (self.botModel.PrimaryPart.Position - dest).Magnitude < 5 then
				self.isPathing = false
				self.movementTarget = nil
			end		
		end
		self.isPathing = false --in case we exit due to death
	end)

end

can you please show a video of the npc tweaking?

1 Like

Sure thing. Tried to upload a video, but it wouldnt let me for some reason so here’s a gif. Admittedly a choppy gif, but it does show the skipping forward during MoveTo that I mentioned
(Uploads keep erroring out, heres a link to the gif that should work temporarily)

Edit: Upload isnt showing…