how would I make something similar to how to eggs pop out of where your standing on go perfectly in a circle? not sure how to achieve this! any help would be great!
First thing would be to break up your circle into how ever many parts you want. Your video has 8 so let’s go with that.
local segments = 8
local angle = 360 / segments --> 45 of course; 360 is a full circle
Now, since Lua’s math functions work with radians convert the angle to radians.
angle = math.rad(angle)
Now, for each part to be made (segment) we can create a new part and using the angle, we multiply it by which ever iteration (segment) we are on.
We can get the X and Y offsets by doing math.sin(angle) and math.cos(angle) respectively.
for i = 1, segments do
local targetAngle = angle * i
local x, y = math.sin(targetAngle), math.cos(targetAngle)
Now, all we have to do is offset the part from the initial part’s position:
local newPart = part:Clone()
newPart.Position = part.Position + Vector3.new(x, 0, y) -- x, 0, y is a vector whose magnitude is 1 (it's a unit vector)
newPart.Parent = workspace
end
Right now that spawns a part that is 1 stud from the centre part in a circular direction:
If you want it to be further away you can multiply x and y or the vector by larger numbers
local x, y = math.sin(targetAngle) * 10, math.cos(targetAngle) * 10
-- or later in the script when positioning the part,
newPart.Position = part.Position + Vector3.new(x, 0, y) * 10
This should scale up/down appropriately depending on how many segments you want.
For example, 100:
6:
Hey, so I was looking at it and its doing this, am I doing something wrong?
local segments = 8
local angle = 360 / segments
local radians = math.rad(angle)
for i = 1, segments do
local targetAngle = angle * i
local x, y = math.sin(targetAngle) * 4, math.cos(targetAngle) * 4
local newPart = part:Clone()
newPart.Position = part.Position + Vector3.new(x, 0, y)
newPart.Parent = workspace
end
This should be radians * i, not angle. My bad.
Ah, Thank you so much for the help and have an amazing day!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.