Curve calculation

Hello guys,
I’ve been trying to fix this problem for weeks but I can’t find an answer anywhere. How can I ensure that the Bezier curve always only stays on one side or the rotation of the parts. As soon as the end part goes behind the start part, the curve turns from the point where it is over 180 degrees. But I want the curve to stay on the side:

local StartPart = workspace.StartPart
local ControlPart = workspace.ControlPart
local EndPart = workspace.EndPart

local numPoints = 10

for i = 1, numPoints do
	local t = i / numPoints
	local slerpPos = CFrame.new(
		StartPart.Position:Lerp(ControlPart.Position, t):Lerp(ControlPart.Position:Lerp(EndPart.Position, t), t)
	)

	local newPart = Instance.new("Part")
	newPart.Size = Vector3.new(1, 1, 1)
	newPart.Anchored = true
	newPart.Position = slerpPos.Position

	local nextT = (i + 1) / numPoints
	local nextPos = CFrame.new(
		StartPart.Position:Lerp(ControlPart.Position, nextT):Lerp(ControlPart.Position:Lerp(EndPart.Position, nextT), nextT)
	)
	local direction = (nextPos.Position - newPart.Position).Unit

	newPart.CFrame = CFrame.lookAt(newPart.Position, newPart.Position + direction)

	newPart.Parent = workspace
end

Here is the problem as a picture:

1 Like

From the image you sent, do you just want the parts to maintain their position but keep a fixed orientation?

Yes, they should stay on one side and not rotate 180 degrees

when you say stay on one side, do you mean in relation to the worldspace so it’s not curved on the X/Z axis or the actual local space of the brick to be a consistent orientation?

Yes, exactly, I want to make a roller coaster construction system and would like to include loops, but it always turns to the other side at a certain point

1. newPart.CFrame = CFrame.new(newPart.Position)
2. newPart.CFrame = CFrame.lookAt(newPart.Position, newPart.Position + direction)

At the end of your code, replace the 2 with 1

But then they no longer rotate with the curve:

1 Like

Is it not rotating with the curve in the original image on the post?

1 Like

Here there the parts rotate, but just wrong

Why is that rotating wrong? Can you maybe draw how it’s supposed to be rotated on the boxes?

1 Like

Maybe you can see it better now:

And that’s the correct or incorrect behavior?

Not correct because the curve turns so strangely after 180 degrees


I added a marker to show the top of the part, this is the issue right?
because if it’s the issue, the video you sent is the correct behavior?

1 Like

Yes, that is exactly the problem

1 Like

It turns strangely because of the ControlPart’s position. Adjust it

1 Like

It is always when the EndPart is positioned behind the StartPart

Yes, but how… I’ve already tried so many things

Wym behind the start part?

Nevermind thought Spins just so weird when it’s behind it