-
What do you want to achieve? Moving a part along a spline
-
What is the issue? I have no idea how
I have tried some solutions but they look extremely glitchy
Just looking for pointers in the right directions
What do you want to achieve? Moving a part along a spline
What is the issue? I have no idea how
I have tried some solutions but they look extremely glitchy
Just looking for pointers in the right directions
Are you talking about a mechanical spline?
If the spline and the Part are going to be connected try using a PrismaticConstraint and set it to Servo so you can select what points the Part moves to.
The first thing that comes to mind when I see this is Bézier Curves. The underlying idea is that you linearly interpolate from P0
to P1
, then P1
to P2
, P2
to P3
, and so on until you reach the last point. This gives you a new set of points, and you repeat this process until you have only one point left:
Here’s a relatively simple function I wrote for this purpose a while back:
--Bezier curve
--Essentially a linear interpolation between points, recursively, until only one point remains
function getBezier(points, progress)
--Calculate number of final points and prepare an array for them
local points = points
local nPoints = #points - 1
--Reduce number of points until there's only one left
--With only one remaining point, nPoints will be 0 since it's
--the number of points to be stored in the next iteration
while (nPoints > 0) do
local pointsOut = table.create(nPoints, Vector3.new())
local i
for i = 1, nPoints do
--Get points
local p0 = points[i]
local p1 = points[i+1]
--Store linearly interpolated point
pointsOut[i] = p1*progress + p0*(1-progress)
end
--Store new points and number of points for the next iteration
points = pointsOut
nPoints = nPoints - 1
end
--Return the last point
return points[1]
end
Hopefully this helps!