Pets movement system jittering

I have a pet system that uses align position and align orientation. My issue is that the pets are super jittery. Here is a video of it.

Here is the code that sets the target position for the two body movers.

		targetCF = Player.Character.HumanoidRootPart.CFrame * CFrame.new(Vector3.new(xOffset,0,3*math.floor(count))) -- * CFrame.Angles(0, 0, 0)

		local TargetPos = targetCF.Position
		local RayParams = RaycastParams.new()
		RayParams.FilterDescendantsInstances = {Player.Character.PetFolder}
		RayParams.FilterType = Enum.RaycastFilterType.Exclude
		RayParams.RespectCanCollide = true

		local PetPosition, PetHeight = petModel:GetBoundingBox()
		PetPosition = PetPosition.Position
		PetHeight = PetHeight.Y

		local RayCast = workspace:Raycast(Vector3.new(TargetPos.X, Player.Character.Head.Position.Y, TargetPos.Z), Vector3.new(0,-20,0), RayParams)
		if RayCast and RayCast.Position then
			local y = RayCast.Position.Y + (PetHeight/2) - (PetPosition.Y - petModel.Center.Position.Y)
			targetCF = CFrame.new(Vector3.new(TargetPos.X, y, TargetPos.Z)) * targetCF.Rotation
		end

		if Player.Character.HumanoidRootPart.AssemblyLinearVelocity.Magnitude > .7 then
			targetCF = CFrame.new(Vector3.new(TargetPos.X, targetCF.Position.Y + math.clamp(math.sin(tick() * 20),-.2,1), TargetPos.Z)) * targetCF.Rotation * CFrame.Angles(-math.rad(MaxRotation * math.sin(tick() * 15)), 0, -math.rad(MaxRotation * math.sin(tick() * 10)))
		end

		petModel:WaitForChild("Center").AlignPosition.Position = targetCF.Position
		petModel.Center.AlignOrientation.CFrame = targetCF

I have tried using a lerp instead of body movers and still run into the same issues. Here are the settings for the body movers

local AlignOrientation = Instance.new("AlignOrientation", Clone.Center)
	AlignOrientation.Attachment0 = Clone.Center.Attachment
	AlignOrientation.Mode = Enum.OrientationAlignmentMode.OneAttachment
	AlignOrientation.Responsiveness = 25
	AlignOrientation.MaxTorque = 25000

	local AlignPosition = Instance.new("AlignPosition", Clone.Center)
	AlignPosition.Mode = Enum.PositionAlignmentMode.OneAttachment
	AlignPosition.MaxForce = 25000
	AlignPosition.Responsiveness = 25
	AlignPosition.MaxVelocity = 1000
	AlignPosition.ApplyAtCenterOfMass = true
	AlignPosition.Attachment0 = Clone.Center.Attachment
	AlignPosition.Position = Player.Character.PrimaryPart.Position

If anyone has any ideas, please let me know.

2 Likes

Have you tried setting the NetworkOwner of the pet to the player?

Yes, the network owner is the player.

I didn’t use network owner … This took me over a year to get down, they move as smooth as glass now. My scripts are loosely based off this system Good Luck!

I tried not using network owner and it didn’t make a difference, I would also prefer to not use depricated instances.

All I know is that way is super super smooth movement. Check out his video, it sold me. Not saying you’re wrong … I’ve never seen pets move as smooth as mine.

Did it a bit different in the loop …
This is a raw snip kind of just showing the loop. The lines above are moved down to show what they are.

local hrp = char.HumanoidRootPart pet.Position = hrp.Position
local bg = Instance.new("BodyGyro", pet)
local bp = Instance.new("BodyPosition", pet)
bp.MaxForce = Vector3.new(huge, huge, huge)
bg.MaxTorque = Vector3.new(huge, huge, huge)
bp.Position = hrp.Position - (hrp.CFrame.RightVector * 4.1)
bg.CFrame = CFrame.new(hrp.Position, hrp.CFrame.LookVector 
	* 10000) * CFrame.Angles(0, math.rad(-3), 0) 
rs.Stepped:Wait()


while true do
	if pet ~= nil then else break end
	if char.Humanoid.Health < 1 then break
	end	rs.Stepped:Wait()
	if pet.Parent == char then
		bp.Position = hrp.Position - (hrp.CFrame.RightVector * 4.1)
		bg.CFrame = CFrame.new(hrp.Position, hrp.CFrame.LookVector 
			* 10000) * CFrame.Angles(0, math.rad(-3), 0)
		rs.Stepped:Wait()
	else break
	end
end

I move this script (the whole thing, not just this snip) into the pet - script disabled, then turn it on … and off they go following. I’m also sure rs.Stepped:Wait() is helping the smoothness.

The code isn’t the problem, what loops are you using, or what events are you connecting to to run this code? Task Scheduling-wise, also is this Server-Sided or Client-Sided

something that might work is TweenService:Create(part, TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, {CFrame = cframe}):Play()