Limit the 'choppiness' of this follower?

Working on a follower system and been experimenting with different methods. This is my current one:

As you can see demonstrated below there seems to be some choppiness on the following mechanic which causes jumps. I was wondering if or how this could be corrected?

    local Player = game:GetService("Players").LocalPlayer
	repeat wait(.1) until Player.Character ~= nil
	local Character = Player.Character
	
	local PetObj = Player:WaitForChild("isPet").Value
	
	local Distance = 5
	
	local TweenService = game:GetService("TweenService")
	
	local tweenInfo = TweenInfo.new(.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
	
	game:GetService("RunService").Stepped:Connect(function()
		local tween = TweenService:Create(PetObj["Base"], tweenInfo, {CFrame = Character["HumanoidRootPart"].CFrame - Vector3.new(0, 3.5, 0) - Character["HumanoidRootPart"].CFrame.LookVector * Distance}):Play()
	end)

https://gyazo.com/0cd4d838e5bb7300609b3806c134bebe

Try manually tweening the CFrame, like so:

local lerpSpeed = 10

game:GetService("RunService").RenderStepped:Connect(function(dt)
	local rootPart = Character.HumanoidRootPart
	local targetCFrame =  Character.HumanoidRootPart.CFrame - Vector3.new(0, 3.5, 0) - rootPart.CFrame.LookVector * Distance
	PetObj.Base.CFrame = PetObj.Base.CFrame:Lerp(targetCFrame, dt * lerpSpeed)
end)

Here’s what I think causes your issue: playing the tween makes it update, moving it along the line towards the character a tiny bit before the frame actually renders. That causes it to be slightly ahead of where it was supposed to be, making it “snap” to a new position on the next frame. Something like this:

instead of this

I don’t know for sure though, let me know if the thing I suggested fixed the issue.

2 Likes