Pet rotating correctly, but falling through the ground (Lerping)

Hello, there.
I am having a hard time getting this pet movement system to work. It’s using :lerp() instead of body movers.

The issue I’m having, is that the pet just falls through the ground and eventually disappears into nothingness. I checked the rotation on it though, and that part seems to work as intended.

Already tried setting network owner to the local player, and idk what else to try.

Here’s the code (localscript):

RunService.RenderStepped:Connect(function(step)
	for i,player in next, game.Players:GetPlayers() do
		local Character = player.Character
		if Character then
			if Character:FindFirstChild("Pets") then
				local hrp = Character:FindFirstChild("HumanoidRootPart")
				local humanoid = Character:FindFirstChild("Humanoid")
				if hrp and humanoid then
					local list = {}
					for i,GamePet in next, Character:WaitForChild("Pets"):GetChildren() do
						table.insert(list,GamePet)
					end
					for i,pet in next, list do
						local newpos = hrp.CFrame.p
						local cf = CFrame.new(newpos)
						cf = cf * CFrame.Angles(0,math.rad((360/player.PlayerData.PetFolder.NumberEquipped.Value)*i),0)
						
						if player.PlayerData.PetFolder.NumberEquipped.Value <= 8 then
							cf = cf + (cf.lookVector * (7)) + Vector3.new(0, 0,0)
						else
							cf = cf + (cf.lookVector * (player.PlayerData.PetFolder.NumberEquipped.Value - 1)) + Vector3.new(0,.5*math.sin(tick()),0)
						end
						cf = CFrame.new(cf.p,cf.p + hrp.CFrame.lookVector)
						
						if humanoid.MoveDirection == Vector3.new(0,0,0) then
							cf = CFrame.new(cf.p, hrp.CFrame.p)
						end
						
						--Cf = Cf:lerp(newcf, .1)
						cf = cf * CFrame.new(0, 0.66 * math.sin(tick()), 0)
						
						local new = pet.PrimaryPart.CFrame:lerp(cf,.1)
						pet:SetPrimaryPartCFrame(new)
					end
				end
			end
		end
	end
end)

If anyone could possibly help me out here, that’d be great :slight_smile:
Thank you!

1 Like

When you did local cf = CFrame.new(newpos) name the variable under something different because when you do cf = cf, it currently is the variable there. So do

local RandomThing = CFrame.new(newpos)
local cf = RandomThing *CFrame.Angles(0,math.rad((360/player.PlayerData.PetFolder.NumberEquipped.Value)*i),0)

Yeah, but it is intended to be cf = cf *

Instead I could just do cf *=

But anyways, thanks for replying so quickly, it didn’t fix it though.

Why exactly are you lerping hm

As pet movement. So pets. Lerping them to follow the character.

Well use welds lerping is a bad idea.

local Pet = – ur pet
local Weld = Instance.new(“WeldConstraint”)
Weld.Part0 = Character.HumanoidRootPart
Weld.Part1 = Pet – the part 1 is the part u want to follow the body
Weld.Parent = Weld.Part0

Problem with welds is, I’d have to destroy and make new ones every time there is 1 less or more pet equipped to give them the correct location. And lerping also offers more smooth pet movement.

I’m a huge fan of Lerping but I wouldn’t necessarily use it for a situation like this and here’s why. When you are doing smooth movement by lerping cframe, you will have to manually replicate that movement because network ownership will no longer apply here. However, if you do that which you totally can do, there’s no need to be using welds here. You can anchor everything and just keep on using SetPrimaryPartCFrame to adjust the model, but you have to do so for every pet in the game on each client which it actually looks like you are already doing!

1 Like

Thanks for helping me out. Anchoring the pets did the job :slight_smile:

1 Like