Faulty Pet Movement

  1. I want my pet to move beside me smoothly.

  2. The pet is glitchy and I don’t know how to fix it.

  3. I’ve used BodyGyro, for MaxTorque and BodyPosition to move the pet, it’s smooth, but the pet moves too slow. I’ve also tried using TweenService, it moves fast, but it’s glitchy. I’ve thought of lerping but it would probably be slow and glitchy.

  4. Basically, I want the pet to move like the pets in Pet Simulator X.

Here is the script, so you can understand better:

local v1 = script.Parent
local u1 = {};
function u1.v2(v3)
	if not v1.Parent.Equipped:FindFirstChild(v3.Name) then
		local v9 = Instance.new("BoolValue");
		v9.Name = v3.Name;
		v9.Value = true;
		v9.Parent = v1.Parent.Equipped;
		if v3 then
			local v4 = v3.Character;
			if v4 then
				local v5 = v4.HumanoidRootPart;
				local v6 = v1:Clone();
				v6.Parent = v4;
				local v8 = Instance.new("BodyGyro", v6);
				v8.MaxTorque = Vector3.new(math.huge, math.huge, math.huge);
				while true do
					local v10 = game:GetService("TweenService"):Create(v6,TweenInfo.new(0,Enum.EasingStyle.Sine,Enum.EasingDirection.Out),{Position = v5.Position + Vector3.new(0, 2, 3); Orientation = Vector3.new(0,v4.Head.Orientation.Y,0);});
					v10:Play();
					wait();
				end;
			end;
		end;
	else
		if v3 then
			local v4 = v3.Character;
			if v4 then
				if v4:FindFirstChild(v1.Name) then
					v4:FindFirstChild(v1.Name):Destroy();
				end;
			end;
			v1.Parent.Equipped:FindFirstChild(v3.Name):Destroy();
		end;
	end	
end;

return u1;

If the script is confusing because of the variable names, please tell me, and I will name them so you will understand.

If anyone has a solution for this, please tell me!
Thank you!

I made this script for pets in one of my games, hopefully it helps:

local petOffset = Vector3.new(2, -1, -2)
petModel = script.Parent

local alignPositionTemplate = Instance.new("AlignPosition")
alignPositionTemplate.Responsiveness = 5
alignPositionTemplate.RigidityEnabled = false

local alignOrientationTemplate = Instance.new("AlignOrientation")
alignPositionTemplate.RigidityEnabled = false


script.Parent.AncestryChanged:Connect(function(child, newParent)
	local possibleHuman = newParent:FindFirstChildWhichIsA("Humanoid")
	if possibleHuman then --assumed that we are inside a player	
		local pet = child
		local charPrimary = possibleHuman.Parent.PrimaryPart --default = rootpart
		local petPrimary = pet.PrimaryPart

		local charOriAttachment = Instance.new("Attachment", charPrimary)
		local charPosAttachment = Instance.new("Attachment", charPrimary)
		charPosAttachment.Position = Vector3.new(2, 1, 2) -- position offset

		local petOriAttachment = Instance.new("Attachment", petPrimary)

		petOriAttachment.CFrame = CFrame.Angles(0, 0, 0)
		local petPosAttachment = Instance.new("Attachment", petPrimary)

		local alignPosition = alignPositionTemplate:Clone()
		alignPosition.Attachment0 = petPosAttachment
		alignPosition.Attachment1 = charPosAttachment
		alignPosition.Parent = petPrimary

		local alignOrientation = alignOrientationTemplate:Clone()
		alignOrientation.Attachment0 = petOriAttachment
		alignOrientation.Attachment1 = charOriAttachment
		alignOrientation.Parent = petPrimary

		petPrimary:GetNetworkOwner(game:GetService("Players"):GetPlayerFromCharacter(possibleHuman.Parent))
		-- set the network owner to the player, this ensures that the movement is smooth	
	end
end)
1 Like

It works so well, thank you!⠀⠀

1 Like

I was also wondering if you knew how to make it hover up and down.