How To Make A Part Move In A Certain Curved Path

Using pathfinders modifiers, you can use pathfinding service to make sure that the part wouldnt calculate any other path to get other than to get through the curve. This is just the one of the best ways of doing this.

You’d simply tween the part along a line (no math required) perform a horseshoe like movement on the part (will require math) and then tween the part along a line parallel to the previous line (no math required).

Spline (subset of Bezier Curves)

local function calculatePos(x,a,b,c,d)
	return a + x*(b + x*(c + x*d))
end

local function GetHermiteCoefficients(p0, p1, m0, m1)
	return p0, m0, 3*(p1 - p0) - 2*m0 - m1, 2*(p1 - p0) - m0 - m1
end

local function GetCentripetalCRCoefficients(p0, p1, p2, p3)
	return
		p1,
		0.5*(p2 - p0),
		p0 - 2.5*p1 + 2*p2 - 0.5*p3,
		1.5*(p1 - p2) + 0.5*(p3 - p0)
end

--[[
	example:
		
	a_to_b = CatmullRom(a, a, b, c)
	b_to_c = CatmullRom(a, b, c, d)
	c_to_d = CatmullRom(b, c, d, d)
--]]

local v3 = Vector3.new

local points = {
	v3(0,0,0),
	v3(5,0,0),
	v3(2,7,3),
	v3(4,5,6),
}

local new = Instance.new
local pSize = v3(0.2,0.2,0.2)
local size = #points
for i = 1,size-1 do
	local b = points[i]
	local a = points[i-1] or b
	local c = points[i+1] or b
	local d = points[i+2] or c
	
	a,b,c,d = GetCentripetalCRCoefficients(a,b,c,d)
	
	for j = 0,1,0.05 do
		local p = new("Part")
		p.Size = pSize
		p.Anchored = true

		
	
		p.Position = calculatePos(j,a,b,c,d)
		p.Parent = workspace
	end
	
	local p = new("Part")
	p.Size = pSize*2
	p.BrickColor = BrickColor.new("Bright red")
	p.Anchored = true

	p.Position = points[i]
	p.Parent = workspace
end

local p = new("Part")
p.Size = pSize*2
p.BrickColor = BrickColor.new("Bright red")
p.Anchored = true

p.Position = points[size]
p.Parent = workspace
3 Likes
local Part = script.Parent
local Tweens = game:GetService("TweenService")

task.wait(5) --Wait for load.

local Tween = Tweens:Create(Part, TweenInfo.new(1, Enum.EasingStyle.Linear), {Position = Part.Position + Vector3.new(20, 0, 0)})
Tween:Play()
Tween.Completed:Wait()
--Perform horseshoe movement here.
local Tween = Tweens:Create(Part, TweenInfo.new(1, Enum.EasingStyle.Linear), {Position = Part.Position + Vector3.new(-20, 0, 0)})
Tween:Play()
Tween.Completed:Wait()

I’ll get around to scripting the horseshoe movement later.

Re-read:
https://developer.roblox.com/en-us/api-reference/datatype/TweenInfo
Due to advancements in Roblox, and through the huge support from it’s community, we now have an exclusive feature called TweenInfo.Reverses. Now this can be used to circumvent the need for a second tween. An example of this would be your code, surprisingly.

No because that would disrupt the horseshoe movement which needs to occur between each tween.

I added a comment detailing as such and explicitly stated that I’ll get around to finishing the script later.

Keep at it buddy, I know Geometry can be hard. Since you are tweening back to the original position, it sadly would not make the shape “explicitly” shown in the OP. The man even presented an arrow showing where to go next (would hate to see you driving), now in the future make sure you are actually reading what someone would like, always double check your work. Reminder:
image
NOT (they are different)
image
Try, please, not to go Off-Topic.

I’ll get around to scripting the horseshoe movement later.

I guess this language is too difficult for you to understand.

Your graph is wrong as well (currently the part just moves back and forth along the same line). I’ll restate for the third time, I will get around to finishing the horseshoe movement of the script later.

I would love to see this prestigious “horseshoe” of yours, I think it would make a relevant contribution to this thread. I don’t believe a linear tween has any curvature at all, this is definitely odd due to the title of this thread “… Curved Path”. I hope you know the difference between erect and flaccid.

Thank you all for your responses, I have learned a lot from each post.
I have a question.
Let’s say we get the bezier curve that I want the object to move along. How do we actually move the object along the curve?

using t. 0 < t > 1

1 = Destination