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.