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

How can I make a part circle or "orbit" around in a perfect circle?

Asked by 5 years ago

Hi! I'm trying to make a part spin around in a perfect circle and here are the things I've tried:

local circle_motion_Z = 0
local circle_motion_X = 0

while true do
    script.Parent.Position = script.Parent.Position + Vector3.new(circle_motion_X,0,circle_motion_Z)
    circle_motion_Z = circle_motion_Z + 0.001
    circle_motion_X = circle_motion_X + 0.0005
    wait(0.01)
end

And another one I'd thought work:

while true do
    script.Parent.Position = script.Parent.Position + Vector3.new(0.1,0,math.pi)
    wait(0.01)
end

I've tried other things but I think those two will be most important in this situation. I don't know if I'm doing this right or wrong, I was thinking about using Tweening but that probably wouldn't work for moving a part in a circular motion.

Thanks for helping me! ~Chez_Guy :)

0
x, y = cos(ang), sin(ang) EpicMetatableMoment 1444 — 5y

1 answer

Log in to vote
2
Answered by
xPolarium 1388 Moderation Voter
5 years ago
Edited 5 years ago

My method might be a little messy but is quick to the point.

Using two anchored parts named 'Origin' and 'Orbit' in workspace:

local origin = workspace:WaitForChild("Origin") --The center part we're orbiting
local orbit = workspace:WaitForChild("Orbit") --The part that will be moving

local i = 0 --Increment

while true do
    --Start at origin then apply an offset using Angles()
    target.CFrame = CFrame.new(main.Position) * CFrame.Angles(0, i, 0) * CFrame.new(0, 0, 5)

    --Increment i by 5 degrees every wait()
    i = i + math.rad(5)
    wait()
end
0
shouldn't you use SetPrimaryPartCframe with the orgin as the primary part? theking48989987 2147 — 5y
0
That worked!! Thank you so much! Chez_Guy 67 — 5y
0
@theking48989987, You would if this was a model. I'm using two normal Parts here. xPolarium 1388 — 5y
Ad

Answer this question