Rotating a part around another part as that part moves causes the rotated one to increase it's radius?

I dont know how to attempt a solid workaround with this. I need it to stay at a certain length from the main block while the main block moves. Might end up using alternatives like linear-velocities and such…

Code

repeat task.wait()
	script.Parent.PivotOffset = script.Parent.CFrame:Inverse() * workspace:WaitForChild("MainPart").CFrame
	script.Parent:PivotTo(script.Parent:GetPivot() * CFrame.Angles(0,math.rad(1), 0))
until nil

I couldnt get your original method to work so instead heres a alternative solution, sorry if this overcomplicates things.

local rotatingpart = workspace:WaitForChild("RotatingPart")
local centerpart = workspace:WaitForChild("CenterPart")

local angle = 0
local speed = math.rad(95)
local radius = 5

while true do
    task.wait()
    angle = angle + speed * 0.1
    rotatingpart.Position = centerpart.Position + Vector3.new(radius * math.cos(angle), 0, radius * math.sin(angle))
    
    local lookvector = (centerpart.Position - rotatingpart.Position).unit
    rotatingpart.CFrame = CFrame.new(rotatingpart.Position, rotatingpart.Position + lookvector)
end

You can construct the CFrame differently to produce this effect:

local mainPart = workspace:WaitForChild("MainPart")
local rotation = 0

while task.wait() do
	script.Parent.CFrame = mainPart.CFrame * CFrame.Angles(0, math.rad(rotation), 0) -- Rotate part
	script.Parent.CFrame *= CFrame.new(0, 0, 5) -- Move part forwards (5 is the radius)
	
	rotation += 1 -- Add rotation (1 is the speed)
	
	if rotation > 360 then
		rotation = 0
	end
end

Not sure why you would need to use CFrame.lookAt (or as you put it in your code, CFrame.new(pos, lookAt)) because we already can reference the center part. This just seems inefficient.

It was that simple… my brain was hurting for hours wow! thank you!

1 Like

No problem, if it worked, please give it the solution to let others know.

If you have any other questions, feel free to ask.

1 Like

Oh and to change the speed, just change rotation += 1 to rotation += 5 or whatever value you want.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.