How to get pets to actually move with player nicely vs snapping to instant position

I want my pets to follow the character in a more natural way. This is what I am wanting to achieve

However, this is what I got so far
ezgif.com-gif-maker (38)

The pets kinda form a circle, and as I rotate my character, they all rotate with me. The should ideally stay in the same position and only move as I move, and they shouldn’t always be on the specific position

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local Player = Players.LocalPlayer

local fullCircle = 2 * math.pi
local radius = 6

local function getXAndZPositions(angle)
	local x = math.cos(angle) * radius
	local z = math.sin(angle) * radius
	return x, z
end

RunService.Heartbeat:Connect(function()
	if not Player.Character then return end
	
	if not Player.Character:FindFirstChild("HumanoidRootPart") then return end
	
	for i, part in pairs(workspace.Pets:GetChildren()) do
		local angle = i * (fullCircle / #workspace.Pets:GetChildren())
		local x, z = getXAndZPositions(angle)

		local position = (Player.Character:GetPivot() * CFrame.new(x, 0, z)).Position 
		
		part.PrimaryPart.AlignPosition.Position = position
		part.PrimaryPart.AlignOrientation.CFrame = Player.Character:GetPivot()
	end
end)
1 Like