Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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 :)

1 comment

0

x, y = cos(ang), sin(ang)

1 answer

✓ Accepted answer

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

3 comments

0

shouldn't you use SetPrimaryPartCframe with the orgin as the primary part?

0

That worked!! Thank you so much!

0

@theking48989987, You would if this was a model. I'm using two normal Parts here.

This discussion is preserved as it was. New answers, comments, and votes are closed.