I’m trying to make a system that creates “3D text labels”, there’s a part corresponding to each letter in the alphabet, however some of the letters are overlapping each other and aren’t rotated correctly.
Current code:
return function(letters, origin, properties)
local letterSpacing = 1.5;
local parts = {};
for i = 1, #letters do
local corresponding = script:FindFirstChild(letters:sub(i, i));
if corresponding ~= nil then
table.insert(parts, corresponding);
end;
end;
local model = Instance.new("Model")
model.Name = letters:match("%s") and "Sentence" or "Word";
local boundingBox = Instance.new("Part")
boundingBox.Anchored = true;
boundingBox.CanCollide = false;
boundingBox.Transparency = 1;
boundingBox.Parent = model;
local previous = parts[1];
for _, part in pairs(parts) do
for property, value in pairs(properties) do
part[property] = value;
end;
part.Parent = model;
part.Position = Vector3.new(
letterSpacing*(#model:GetChildren() - 1) + previous.Size.X, 0, 0);
previous = part;
end;
boundingBox.Position = model:GetBoundingBox().Position;
boundingBox.Size = model:GetExtentsSize();
model.PrimaryPart = boundingBox;
model:SetPrimaryPartCFrame(CFrame.new(origin));
return model;
end;
It first takes the string piece by piece to find which part they correspond to.
It creates a model and bounding box, so it can later be positioned to the origin.
Each letter is spaced like this:
(letterSpacing * (number of letters in model - 1) + previousPart.Size.X, 0, 0)