#need help positioning parts around a target part in a circle formation

1 messages · Page 1 of 1 (latest)

jade cedar
#

so i have two variables I want to use:

local desired_amount = 4--how many parts i want to place around the target part
local distance = 5--distance away from target part to be placed in studs

so in this example, i want 4 parts to be placed around a targetpart in a circle formation.

my main problem is the math behind properly position the parts along a circle formation, I know I need to use distance as radius from the center(target part) and something with math.pi

I am really struggling with wrapping my head around this and I cant find any resources on google

#
local target = workspace:WaitForChild('Target')
local clone = game.ReplicatedStorage:WaitForChild('Clone')

local desired_amount = 4 --how many parts i want to place around the target part
local distance = 30 --distance away from target part to be placed in studs

local currentPart
local circleAngles = 360 / desired_amount


for i = 1, desired_amount do
    local pos = circleAngles * i
    local newPart = clone:Clone()
    newPart.CFrame = --idk
    newPart.Parent = workspace
end

what ive got so far

manic wave
#

You really only need to care about 1 of the positions, not all 4, since after you get 1, you can get the next, opposite, and oppositenext

#

So you have a displacement value of 4. From just adding it to the X you get the right, adding it to the Z you get the forward. Adding it backwards gets you the -Z and adding it left is the -X.

Now, what I would do?

Get the center object's lookvector. this is your forward, times it by your displacement.
That's your +Z position.
Displacement times -1 gets you your -Z position.
You already have forward and backwards. now all you need to do is change the position of the value. Currently it looks like this:
Vector3.new(0,0,displacement)
Change it to:
Vector3.new(displacement,0,0)
And you get your X values.