# How I Can Pet Movement Inverse Circle Position

My Full Code

``````local PetsFolder = Instance.new("Folder",workspace)
PetsFolder.Name = "Pets"

local RunService = game:GetService("RunService")

local fullCircle = 2 * math.pi

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

local MainLERP = 0.01;

local LerpMultipier = 1

local function getCirclePoint(ItemNumber,TotalNumber)

if TotalNumber <= 2 then
return (ItemNumber * math.pi)
elseif TotalNumber == 3 then
return (ItemNumber * (math.pi*1.5) / 3)
else
return (ItemNumber * ((2 * math.pi) / TotalNumber))
end

--return (ItemNumber * math.pi) --(ItemNumber * ((2 * math.pi) / TotalNumber))

end

game.ReplicatedStorage.PetActionEvent.OnServerEvent:Connect(function(plr,stat,char,petfolder)
if stat == "Move" then

if PetsFolder:FindFirstChild(plr.Name) and plr.Character then

local hmndrootpart = plr.Character.PrimaryPart

local petsTable = {}

for i,v in pairs(PetsFolder[plr.Name]:GetChildren()) do
if v:IsA("Model") then
table.insert(petsTable,v)
end

end

for i,v in pairs(petsTable) do

if v.ClassName and v:IsA("Model") and v.PrimaryPart and v.PrimaryPart:IsA("BasePart") then

if v:FindFirstChild("PetID") then

local LERP_ALPHA = MainLERP * (char.Humanoid.WalkSpeed / LerpMultipier);

local list = {}

for _, v in pairs(game:GetService("Players"):GetPlayers()) do
for _, q in pairs(v.Character:GetDescendants()) do
if q:IsA("BasePart") then
table.insert(list, q)
end
end
end

for i,v in pairs(PetsFolder:GetDescendants()) do
if v:IsA("BasePart") then
table.insert(list,v)
end
end

local rayParam = RaycastParams.new()
rayParam.FilterType = Enum.RaycastFilterType.Blacklist

rayParam.FilterDescendantsInstances =  list

local raycastResult = workspace:Raycast(v.PrimaryPart.Position, v.PrimaryPart.Position - Vector3.new(0, 100, 0), rayParam)

if raycastResult then
local Object = raycastResult.Instance

if Object then
local petCframe = v.PrimaryPart.CFrame
local characterCframe = hmndrootpart.CFrame

local angle = getCirclePoint(i,#petsTable)

local position = (CFrame.new(hmndrootpart.CFrame * Vector3.new(math.cos(angle) * 5, 0, math.sin(angle) * 5))) --  hmndrootpart.CFrame * CFrame.new(math.sin(angle) * radius, 0 , math.cos(angle) * radius))

local newCframe = petCframe:Lerp(position, LERP_ALPHA)
v.PrimaryPart.CFrame = newCframe
v.PrimaryPart.CFrame = CFrame.new(v.PrimaryPart.CFrame.X, (Object.Position.Y + (Object.Size.Y /2)) + (v.PrimaryPart.Size.Y/2) ,v.PrimaryPart.CFrame.Z)

else
local petCframe = v.PrimaryPart.CFrame
local characterCframe = hmndrootpart.CFrame

local angle = getCirclePoint(i,#petsTable)

local position = CFrame.new(hmndrootpart.CFrame * Vector3.new(math.cos(angle) * 5, 0, math.sin(angle) * 5)) --local position = (hmndrootpart.CFrame * CFrame.new(math.sin(angle) * radius, 0 , math.cos(angle) * radius))

local newCframe = petCframe:Lerp(position, LERP_ALPHA)
v.PrimaryPart.CFrame = newCframe

end

else
local angle = getCirclePoint(i,#petsTable)

v.PrimaryPart.CFrame = CFrame.new(hmndrootpart.CFrame * Vector3.new(math.cos(angle) * 5, 0, math.sin(angle) * 5)) --(hmndrootpart.CFrame * CFrame.new(math.sin(angle) * radius ,0, math.cos(angle) * radius))
local newraycastResult = workspace:Raycast(v.PrimaryPart.Position, v.PrimaryPart.Position - Vector3.new(0, 100, 0), rayParam)

end

else

end

end

end

end
end
end)

local function setNetworkOwnerOfModel(model, networkOwner)
for _, descendant in pairs(model:GetDescendants()) do
if descendant:IsA("BasePart") then
if descendant:CanSetNetworkOwnership() then
descendant:SetNetworkOwner(networkOwner)
end
end
end
end

else
end

end)

end
end)

local newPlayerFolder = Instance.new("Folder",PetsFolder)
newPlayerFolder.Name = plr.Name

end)

game.Players.PlayerRemoving:Connect(function(plr)

if PetsFolder:FindFirstChild(plr.Name) then