TruyalYT
(TruyalYT)
December 23, 2023, 9:35pm
#1
Hi, I’m currently trying to make a Bezier curve that rotates around its own axis. I almost made it but somehow it ends up straight again but it should stay rotated at the end:
local rotationStep = Vector3.new(EndPart.Rotation.X / numPoints, EndPart.Rotation.Y / numPoints, EndPart.Rotation.Z / numPoints)
local rotationOffset = Vector3.new(
math.rad(rotationStep.X * (i) * math.sin(math.pi * (i - numPoints) / numPoints)),
math.rad(rotationStep.Y * (i) * math.sin(math.pi * (i - numPoints) / numPoints)),
math.rad(rotationStep.Z * (i) * math.sin(math.pi * (i - numPoints) / numPoints))
)
newPart.CFrame = newPart.CFrame * CFrame.Angles(rotationOffset.X, rotationOffset.Y, rotationOffset.Z)
1 Like
Try using a loop like this:
local rotationStep = Vector3.new(
math.rad(EndPart.Rotation.X / numPoints),
math.rad(EndPart.Rotation.Y / numPoints),
math.rad(EndPart.Rotation.Z / numPoints)
)
for i = 1, numPoints do
local rotationOffset = Vector3.new(
rotationStep.X * i,
rotationStep.Y * i,
rotationStep.Z * i
)
newPart.CFrame = newPart.CFrame * CFrame.Angles(rotationOffset.X, rotationOffset.Y, rotationOffset.Z)
end
1 Like
TruyalYT
(TruyalYT)
December 23, 2023, 9:49pm
#3
Oh thank you, do you know how I can move this a little more to the middle. So that it is more straight at the beginning and end for the next rail:
See if this does the trick
local rotationStep = Vector3.new(
math.rad(EndPart.Rotation.X / numPoints),
math.rad(EndPart.Rotation.Y / numPoints),
math.rad(EndPart.Rotation.Z / numPoints)
)
for i = 1, numPoints do
local t = math.sin(math.pi * (i - 1) / (numPoints - 1))
local rotationOffset = Vector3.new(
rotationStep.X * t,
rotationStep.Y * t,
rotationStep.Z * t
)
newPart.CFrame = newPart.CFrame * CFrame.Angles(rotationOffset.X, rotationOffset.Y, rotationOffset.Z)
end
Oh sorry, never mind that, read the question wrong.
Is this 2 rails connected to each other?
TruyalYT
(TruyalYT)
December 23, 2023, 9:59pm
#8
So it should rotate in the middle like this:
So you want the other end to be like 90 degrees rotated compared to the beginning?
TruyalYT
(TruyalYT)
December 23, 2023, 10:02pm
#10
No, that’s not what I mean, it has nothing to do with it, it’s just not supposed to rotate along the entire rail like this:
So that the rotation in the middle is strong so that such edges do not arise:
Could you try this:
local rotationStep = Vector3.new(
math.rad(EndPart.Rotation.X / numPoints),
math.rad(EndPart.Rotation.Y / numPoints),
math.rad(EndPart.Rotation.Z / numPoints)
)
for i = 1, numPoints do
local progress = (i / numPoints) ^ 2
local rotationOffset = Vector3.new(
rotationStep.X * progress,
rotationStep.Y * progress,
rotationStep.Z * progress
)
newPart.CFrame = newPart.CFrame * CFrame.Angles(rotationOffset.X, rotationOffset.Y, rotationOffset.Z)
end
TruyalYT
(TruyalYT)
December 23, 2023, 10:07pm
#12
Now is the Rotation at the End
Hmmm, try a quadratic ease-out function
local rotationStep = Vector3.new(
math.rad(EndPart.Rotation.X / numPoints),
math.rad(EndPart.Rotation.Y / numPoints),
math.rad(EndPart.Rotation.Z / numPoints)
)
for i = 1, numPoints do
local t = i / numPoints -- Normalized progress (0 to 1)
local easeOutProgress = t * (2 - t) -- Quadratic ease-out
local rotationOffset = Vector3.new(
rotationStep.X * easeOutProgress,
rotationStep.Y * easeOutProgress,
rotationStep.Z * easeOutProgress
)
newPart.CFrame = newPart.CFrame * CFrame.Angles(rotationOffset.X, rotationOffset.Y, rotationOffset.Z)
end
I am not sure what else could get that done
TruyalYT
(TruyalYT)
December 23, 2023, 10:14pm
#15
It’s a little better but still there are these edges at the beginning with a new rail afterwards