I am trying to have a point generate a curve that is being directed to another point (also taking into account the rotation of the parts). I have the code below which works for most angles however there seems to be an interval where it does not follow the ‘circle’ i generated. Ive spent a while attempting to fix it and im completely out of ideas. Let me know if you have any questions
local res = 5;
local angle
local radius = 2;
local parts = {}
--Generates the parts that will be curved
for i = 1, res, 1 do
local p = Instance.new('Part');
p.Anchored = true;
p.Parent = workspace
p.Size = Vector3.new(.6,.1,.1)
parts[#parts + 1] = p;
end
local a = workspace.A
local b = workspace.B
while wait() do
local x,y,z = CFrame.lookAt(a.Position, b.Position):ToOrientation()
angle = y;
local offSet = math.rad(a.Orientation.Y);
local cPos;
angle -= offSet
if angle > 0 then
angle = (math.pi - angle)
cPos = (a.CFrame * CFrame.new(-Size.X/2, Size.Y/2 , Size.Z/2)).Position;
elseif angle < 0 then
angle = -math.pi - angle
cPos = (a.CFrame * CFrame.new(Size.X/2, Size.Y/2 , Size.Z/2)).Position;
else
cPos = (a.CFrame * CFrame.new(Size.X/2, Size.Y/2 , Size.Z/2)).Position;
end
local steps = angle / res
for i,p in ipairs(parts) do
local step = steps * (i);
step -= math.rad(a.Orientation.Y)
local position = Vector3.new(math.cos(step) * radius ,0, math.sin(step) * radius) * (angle / math.abs(angle)) + cPos;
p.Position = position;
p.Rotation = Vector3.new(0, 180 - math.deg(step) ,0)
end
end