Lerping CFrames of multiple npc models makes some of them stutter

Hi everyone,
I have a problem that I’ve been trying to fix for a couple of days now, I have looked at dozens of forum threads with similar issues, but nothing that I’ve found there helped me.

The issue is this: I have some npc characters follow the player, and for some reason, all but one have jittery movement. The weirdest thing is that the first character moves smoothly enough, but any that are added after that stutter. Shown below.

The following behaviour is done on the client with a local script. I iterate through the followers with a for loop, and lerp their root part’s cframes. The root part cframes’ goal is the position of the red spots behind the player (those will be invisible in game). They also rotate towards the spots to look at them. Here’s the code that moves the character’s cframes:

for i, bean in pairs(followers) do
	local root = bean.RootPart
	local x, y, z = CFrame.lookAt(root.Position,Vector3.new(spots[i].Position.X,root.Position.Y,spots[i].Position.Z)):ToEulerAnglesXYZ()
	local goalCF = CFrame.new(Vector3.new(spots[i].Position.X,root.Position.Y,spots[i].Position.Z)) * CFrame.Angles(x,y,z)
		
	root.CFrame = root.CFrame:Lerp(goalCF,0.09)
end

This code is within a Heartbeat.
Even further context: The characters are spawned by a server script and put into a folder within the workspace. When the follow button is clicked, the given character gets moved to a different folder, where they get handled by the local script. Should I handle everything on the server? I wanted to have the following done on the client for more smoothness, but I’m willing to sacrifice it for more stable movement.
This will be a single player game, so I don’t really care about replicating things between clients.

I’ve tried switching to RenderStepped, Stepped, multiplying lerp alpha by dt, using tweens, and probably more I can’t recall off the top of my head. I’m still open to any and all suggestions though, since maybe I didn’t implement them right for my specific issue.

I would greatly appreciate any and all help to fix the stuttering/jittering movement of the follower characters.

it will be bad but how about trying physic with attatching ropes or spring to them and make npc follow player by automaticly (this will work good bcus it is single player)

Right, I did try to use AlignPosition, but then the characters would just get stuck in place or just vibrate. I think that might have to do with discrepancies between the server and client? I’ve tried to set the network owner for the followers to the player or nil, and neither had any impact. Just now also tried to have the follower behaviour be in a server script, also doesn’t solve the issue.

So a few days ago, after more digging around, I found probably the obvious answer in a thread with a title that seemed unrelated to my problem: Tweening model while also using AnimationController resulting in jittery movement - #18 by rapmilo

Over the past few evenings I have been redoing my code and cleaning it up. The little characters aren’t created on the server anymore, they’re also not manipulated by both the server and client at once. They’re created on the client and their CFrames are calculated only on the server, while the client just updates them accordingly through lerping. Now the movements are smooth enough for my liking.

1 Like

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