I am attempting to make a pet system that automatically places the pets based on how many there are. I used this devforum post Having multiple 'pets' at once? - #5 by SovereignFrost
I copied the math and double checked it but for some reason when I run my game and equip multiple pets they perform weirdly like this.
here is the funciton the gets called every heartbeart.
local function updatePetPositions(player)
local numberOfPetsEquipped = 0
for _,v in ipairs(player.PlayerPets:GetChildren()) do
local petData = HttpService:JSONDecode(v.Value)
if petData.isEquipped then
numberOfPetsEquipped += 1
local newPosition = (player.Character.HumanoidRootPart.CFrame * CFrame.new(Utilities.GetPointOnCircle(5, 360/numberOfPetsEquipped))).Position - Vector3.new(0, player.Character.HumanoidRootPart.Size.Y / 2, 0)
newPosition = newPosition + Vector3.new(0, math.sin((T - tick())) / 7)
local newGyro = player.Character.HumanoidRootPart.CFrame
local petObj = petCache[petData.petId]
petObj:setPetPosition(newPosition)
petObj:setBodyGyro(newGyro)
end
end
here is the GetPointOnCirlce function
function Utilities.GetPointOnCircle(CircleRadius, Degrees)
return Vector3.new(math.cos(math.rad(Degrees)) * CircleRadius, 0, math.sin(math.rad(Degrees)) * CircleRadius)
end
I get no errors.