Hi all! I’ve recently been working on scripting a curve plugin, to aid in building curves. It is going great, however, there are random gaps in-between the parts in the curve:
Basically, I generate the curve, and plot points routinely along the path. Then, I am connecting the points with parts using the function below. But why are there the gaps?
local NewFolder = --The folder holding the pre-plotted points along the bezier curve.
local FinalFolder = --The folder that ends up holding the final parts.
local Increment = 1/PartCount -- where part count is the number of pre-plotted parts along the curve.
local Start = Increment
local JustCreated = nil
local function StretchPart()
local pos1 = nil
local pos2 = nil
if JustCreated == nil then
pos1 = NewFolder:FindFirstChild(tostring(0)).Position
Start = 0 + Increment
else
pos1 = NewFolder:FindFirstChild(tostring(Start)).Position
--pos1 = JustCreated.Position
Start = Start + Increment
end
if Start < 1 then
pos2 = NewFolder:FindFirstChild(tostring(Start)).Position
local newpart = Instance.new("Part")
--Part front at pos1 and back and pos2
local v = (pos1 - pos2)
newpart.Anchored = true
newpart.CanCollide = false
newpart.Size = Vector3.new(CurvePart1.Size.X,CurvePart1.Size.Y,v.Magnitude)
newpart.CFrame = CFrame.new(pos2 + 0.5*v, pos1)
newpart.Material = NewFolder:FindFirstChild(tostring(Start)).Material
newpart.Color = NewFolder:FindFirstChild(tostring(Start)).Color
newpart.Parent = FinalFolder
JustCreated = newpart
wait()
StretchPart()
end
end
Any help at all is greatly appreciated! I am so close to being done, I just need to fix this error with the gaps between the parts. Thank you!
I know that F3X building tools have a feature that allow you to orientate from a different centre of rotation - usually from a corner of a part rather than the centre of the object itself. I’m not really sure how this is achieved but that could be a good solution if you find out.
Yeah, I’m going to have to keep experimenting/messing around with it, until I eventually find a solve. I was hoping someone on the forum would have had a similar problem, and know the solve. I need to find a way to replicate movement from a corner, you are right.
local RotatePart = workspace.RotatePart
local Offset = CFrame.new(hinge.Size.X/2, 0, hinge.Size.z/2)
local invHingeOffset = Offset:Inverse()
local baseCFrame = hinge.CFrame*Offset
local function SetHingeAngle(angle)
RotatePart.CFrame = baseCFrame*CFrame.Angles(0, angle, 0)*invHingeOffset*CFrame.new(0,0,RotatePart.Size.z)
end
local angle = 0
while wait() do
angle += 0.05
SetHingeAngle(angle)
end
Which has this effect:
There might be a better way of doing it, but it seems to work.
(In fact I expect you could achieve better results using ToWorldSpace/ToObjectSpace)
@PerilousPanther had it right the first time. The easiest way is to shift all the parts by half their width so their edges align. You were shifting them by half their length. That will tighten the curve to fill the gaps.
However, that would change the curve so it would no longer touch the two points in the middle, but rather on the edge. If that works for you, great.
If it doesn’t, you’ll need to post more complete code, because what you have is missing some crucial details (such as how you actually loop through positions and calculate the next parts positions other than the start).
If you think about it, you are creating a curve from point A to point B and placing Parts on segments along that curve.
Draw a curve on a piece of paper, then put pieces of paper shaped like your Parts centered on that line at the ends. The outer edges travel around a greater curve, so they are going to be farther apart at their outer edge.
To add to @nicemike40’s comment, if you add half the thickness of the Parts in the beginning then calculate the outer curve, and shift your Parts back in to place the outer edges at those points then you should be fine.
I got it working finally. Thanks to @PerilousPanther for your answers (which helped a lot), and @nicemike40 and @Scottifly for both helping break down his answer into something I understood a bit better (I can have a bit of a thick head sometimes).
Before, I was attempting to change the length of the parts to cover up the gap. However, I ended up doing as all of you suggested, and shrinking the position by half the width, to get:
newpart.CFrame = CFrame.new(pos2 + .5*v, pos1) * CFrame.new(-.5,0,0) -- Shrinking it by half the width, as was kindly pointed out to me
All of your answers really helped me, when I launch this plugin I’ll be sure to give credit