Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

CFraming a semi circle with math.pi?

Asked by 9 years ago

Alright. I'll start off by being honest. I don't know anything about math.pi. I need to make a script where it'll generate 24 parts in a semi circle around a middle part. Could anyone help me with this? It would be much appreciated!

0
What do you mean by semi circle - you mean a whole entire circle around a part? Blockeus 68 — 9y
0
Semi-circle = half-circle funyun 958 — 9y
0
Oye Blockeus 68 — 9y
0
I got this. Blockeus 68 — 9y
0
Nope. I already do. funyun 958 — 9y

2 answers

Log in to vote
3
Answered by
funyun 958 Moderation Voter
9 years ago
--Put this in a part
sine, cosine, radians = math.sin, math.cos, math.rad
radius = 30 --Re-define radius here

for i = 1, 24 do
    local part = Instance.new("Part", workspace)
    part.Size = script.Parent.Size
    local angle = radians(180/24) * i
    part.Position = script.Parent.Position + Vector3.new(cosine(angle) * radius, 0, sine(angle) * radius)
    wait()
end

If you haven't taken trigonometry yet, you won't understand this well. Basically, you go through the loop 24 times, adding a part each time you go through. The size will be the original part's size. We're making a semi-circle, so we're going to take 180 and divide it by 24. That's an angle of 7.5. You have to convert this angle to radians. In radian conversion, pi is 180 degrees. You don't need to know that, just convert the degrees to radians with math.rad(). Anyway, the new part's position will be the original part's position, shifted by 3 new values. Now I have to explain sine and cosine to you.

In order to understand sine and cosine, you first need to know what the unit circle is. Let's say you have a coordinate plane; the same one you graph your functions on. You draw a circle with a radius on 1 centered around point (0, 0). That is your unit circle. Now, let's say you take a 30 degree angle from that circle. The beginning of that angle is going to stretch out from the origin of the circle, (0, 0), to the point (1, 0). That's the line that all angles of the unit circle start from. The line that the angle ends on also starts from (0, 0), but where does it end up on the coordinate plane? That's where sine and cosine come up. Cosine is the x value of the coordinate where that other line touches the circle, and sine is the y value. Let's say you had an angle of 90 degrees. The cosine of 90 degrees is 0, and the sine of 90 degrees is 1. 0 over, 1 up. That's where the angle line touches the circle. What about an angle of 270? Cosine will again be 0, and sine will be -1.

There's your little trig lesson for you.

1
I understand the basics of trig! Thank you guys for your help! ObscureEntity 294 — 9y
Ad
Log in to vote
2
Answered by 9 years ago

*Here's a script explaining... *

dist = 100
for i = 1, 360/2 do -- You set up the for loop.
    wait(0.1)
    local p = Instance.new('Part')
    p.Parent = game.Workspace
    p.Size = Vector3.new(4, 4, 4)
    p.Anchored = true
    p.CFrame = CFrame.new(0,0,0)*CFrame.Angles(math.rad(i),0,0)*CFrame.new(0,0,dist);
end

**Explantions: **

  1. At line 1 I'm setting the distance from the middle of the circle which is set at theCframe of (0,0,0) explain during line 8 where i do p.CFrame = CFrame.new(0,0,0)

  2. Line 2 is extremely important because i set a loop starting from 1 to 360/2. 360 degrees is equal to a whole entire turn of a circle divided by the radius which is what the distance from the middle of the circle is set for in line1. So I divded 360/2 to give half of a circle which is equal to 180 degrees .

  3. Line3 is waiting 0.1 of a second till it starts its actions for the rest of the script.

  4. Line 4 creates the part

  5. Line 5 sets the parts into workspace. - but you can just say " workspace " ((p = Instance.new("Part",workspace)), because you can rename your[ workspace] now in roblox studio.

  6. Line 6 sets up the size of the part.

  7. Line 7 stops the part from being affected by roblox physics.

  8. Line 8 It sets the parts cframe which is p to start from the starting place for all parts to be distance from and angled from then i set up CFrame.Angles and use i in math.rad to go through each slight angle through 360. - Search up radians to understand what that does... it's another unit of measure for angles and such that converts degrees to radians . Next I CFrame it again to give each part distance away from the circle. (Remember dist is the radius). Heres a link to radians -> https://en.wikipedia.org/wiki/Radian

*--- Overall you can set the first piece of the cframing (CFrame.new(0,0,0)) in line 8 to to the origin of where you want the circle to go circling around. *

0
Well played. funyun 958 — 9y
0
Lol. Thank you guys! ObscureEntity 294 — 9y
0
lelele my tutorial version is simpler lelele:o probally grammar suckier though and i tried to learn from your with cosine and sine but that confused me with the descriptions unless you had pictures Lelelellee Blockeus 68 — 9y

Answer this question