So, I want to know how to make a certain number of pets form around you in a circle and follow you in that circle while you move around.
I know how to make it so you can have one equipped and follow you but the problems there are, it doesn’t stay in one “corner” of your character and it doesn’t work with multiple pets they will just end up in the same spot
im currently in class rn so i can’t show a script or picture but basically i made a script where it puts a pet behind and to the side of your character but if i add/equip more they will just stay in the same spot and want to know how to make them in a circle
Hopefully you have a basic understanding of CFrame. If I understand correctly, you want a perfect circle formation around the player, depending on how many pets there are. From the way you wrote it, it sounds like you already have a system in place, but their positioning isn’t correct.
That said, here is how I would get the angle and position for each pet.
local PetTable = PetHolder:GetChildren() -- Obviously alter this to fit your environment.
local PetOffset = CFrame.new(0,0,4) -- Change this to offset your pet right.
for i, Pet in pairs(PetTable) do
local Offset = 0 and #PetTable % 2 == 0 or 0.5
local Angle = ((i + Offset) / #PetHolder:GetChildren()) * math.pi * 2
local Position = HumanoidRootPart.CFrame * CFrame.Angles(0,Angle,0) * PetOffset
-- Use this position accordingly.
end
It just depends how you have it set up. Most of my variables, excluding the math, are vague with variable usage. That said, I would recommend using some type of BodyMover to move the pets smoothly.
I took a similar approach as @MattPrograms to the problem. But the only key difference is mine was taking into account the number of pets a player has equipped and ensuring the circle would have a radius large enough to fit the pets without causing for overlap. I made the function in a LocalScript since I assumed that would be the easiest method to set this up because presumably the players would be setting their active pets from a GUI and when it comes to pet movement it will look smoothest when run on the client.
By no means trying to take the spotlight away from @MattPrograms and I would still credit them with this. I was just throwing in the idea of ensuring the pets would have space between each other and not become a big blob around the player in large amounts.
local function setPetNodes(petCount,overlapMultipler)
local rotationOffset = 360/petCount --Determine how much degrees must be seperated between pets
for petNode = 1,petCount do
local currentNode = Instance.new("Part")
currentNode.Name = "Pet Node "..petNode
currentNode.Size = Vector3.new(1,1,1)
currentNode.CFrame = CFrame.Angles(0,math.rad(rotationOffset*petNode),0) * CFrame.new(-game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame.LookVector*math.max(petCount*overlapMultipler,4)) * game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame
local weld = Instance.new("WeldConstraint")
weld.Parent = currentNode
weld.Part0 = game.Players.LocalPlayer.Character.HumanoidRootPart
weld.Part1 = currentNode
currentNode.Parent = game.Players.LocalPlayer.Character
end
end
To those who want to let players equip hundreds of pets enjoy!
The code I posted was used to create the nodes for the pets to follow so you would need to use your AlignPostion and AlignOrientation code snippets and assign each pet to one of those nodes.
local alignPos = Instance.new("AlignPosition")
alignPos.MaxForce = 25000
alignPos.Attachment0 = attachPet
alignPos.Attachment1 = attachChar --Instead of attaching to the character have it attach to one of the nodes
alignPos.Responsiveness = 10
alignPos.Parent = clone
local alignOr = Instance.new("AlignOrientation", clone)
alignOr.MaxTorque = 25000
alignOr.Attachment0 = attachPet
alignOr.Attachment1 = attachChar --Instead of attaching to the character have it attach to one of the nodes
alignOr.Responsiveness = 10