Rotating parts around a center point

I’m trying to create a “rig” where three parts, formed to look like vertices of a triangle, rotate around a center point and converge on the center point after one full rotation. I have the rig working at the coordinates (0, 0, 0), as the way I want it to, however, when I move the center point to a different set of coordinates, such as (5, 0, 5), the rig rotates and converges to the center of the triangle, but they don’t do so around the specified center point; instead: starting at an offset from the specified center point and slowly moving to the specified center point until the parts have converged into the center of the triangle.

This has to be done through CFrame in a for loop and not TweenService, as the player will be able to constantly change where the center point is, depending on their mouse position, and TweenService simply would not work for that.

I’m trying to get the output I want with minimal parts, preferably just the three that will be used later down the line for other things. I’ve tried removing certain aspects of code, adding more, changing how the CFrame values are multiplied together, all ending up with the result I don’t want.

Desired output; coordinates at: (0, 0, 0)
https://gyazo.com/0e501b6bef8bf0254e7f01d9d5713f47

Current output; coordinates at anything else, example used: (5, 0, 5)
https://gyazo.com/90b5e4f5f78205e3c26a24ce252ce929

The current code:

function create_point(name, cframe)
	local point = Instance.new("Part", workspace)
	
	point.Name = name
	point.Size = Vector3.new(1,1,1)
	if cframe ~= nil then
		point.CFrame = CFrame.new(cframe)
	else
		point.CFrame = CFrame.new(0, 0, 0)
	end
	point.Anchored = true
	
	return point
end

center_point = CFrame.new(5, 0, 5)

point_A, point_B, point_C = nil

part_A = create_point("beam_A", point_A)
part_B = create_point("beam_B", point_B)
part_C = create_point("beam_C", point_C)

while true do
	for i = 1,180 do
		rotation_point = center_point * CFrame.Angles(0, math.rad(i*2), 0)
		for k = 1,3 do
			local rotation = (120 * (k-1))
			local new_center = rotation_point * CFrame.Angles(0, math.rad(rotation), 0)	
			local new_pos = new_center * new_center.lookVector * 5
			if k == 1 then point_A = new_pos
			elseif k == 2 then point_B = new_pos
			else point_C = new_pos
			end
		end
		
		local final_point_A, final_point_B, final_point_C = CFrame.new(point_A), CFrame.new(point_B), CFrame.new(point_C)
		
		part_A.CFrame = final_point_A:lerp(center_point, i / 180)
		part_B.CFrame = final_point_B:lerp(center_point, i / 180)
		part_C.CFrame = final_point_C:lerp(center_point, i / 180)
		wait()
	end
end

If you know how to rig models, rig it and animate it in an animation editor, then import the animation and let Roblox handle it for you:

  1. Rig model
  2. Get aniamtion Id
  3. Play animation
  4. Position the triangles where the character is

Another solution is to clone the triangles and positioning them let’s say, 3 studs up the Y axis of where the center point is(so it doesn’t spawn in it’s original position, but, if you just want to converge around the player, set the position to the player position) and it slowly moves down and converges.

The points should converge on a given center point, that will be determined by where the player’s mouse is later down in development. I’m just trying to get the basics of it working for now, where it’ll work at any given coordinate that I give it. I’m not too sure on how to rig models and how I could get the result I want, mathematically correct.

I just found the solution to my own problem. Line 30.

local new_pos = new_center * new_center.lookVector * 5

I completely missed the fact that I needed brackets around new_center.lookVector * 5, so instead of the points being 5 studs away from the center point only, it was also making the position of the entire rig (5, 0, 5) * 5 away, putting the rig at a 25 stud offset away from where it should be.