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