I spent this afternoon researching Bezier Curves and how to create them. And I’ve successfully been able to create these curves and implement a simple method to introduce yaw & pitch into the Bezier curve. The end goal is to use Bezier Curves to create a curve for a Roller Coaster or Helicopter to follow.
What I’m trying to figure out now is how to identify roll into the curve. What I mean by this is the parts “tilt” into the curve similar to a roller coaster or how an airplane turns.
So far I’ve been searching the DevForum for previous articles. This is how I was able to figure out how to introduce pitch and yaw into my Bezier Curve. This is achieved through using CFrame.new(Position,LookAt)
. Both Vector3 values are calculated using the Interpolation equation. With LookAt using a slightly higher Alpha value. Understandably this is not perfect but it will be good enough for my use case. But I was unable to find ways to implement roll.
I’ve also tried to read through some external forums (mainly about Unity) but these seem to use functions accustomed to Unity. So I was a bit lost in how to carry this over into Roblox Studio.
Current Progress Code / Photos
In this photo I would want the parts to tilt to the left slowly to bank into the turn. This is what I’m expecting to get explenations on for.
This code is functioning, but I will post it so people understand my current work. Most of this code is just here to help me visualize the curve to make sure everything is working correctly.
local function createCubicBezierCurve(pointStart,pointMidNear,pointMidFar,pointEnd)
local Folder = Instance.new("Folder")
Folder.Name = "CurveNodes"
Folder.Parent = workspace
for alpha = 0,1,0.01 do
local goal = cubicBezierCurvePoint(pointStart,pointMidNear,pointMidFar,pointEnd,alpha)
local direction = cubicBezierCurvePoint(pointStart,pointMidNear,pointMidFar,pointEnd,alpha+0.005)
local Node = Instance.new("Part")
Node.Anchored = true
Node.CanCollide = false
Node.CFrame = CFrame.new(goal,direction)
Node.Name = "Node @ Alpha: "..alpha
Node.Size = Vector3.new(4,0.25,2)
Node.Parent = Folder
end
end
And this is my mess of a function that gets the points. yet again, nothing broken, just trying to document my progress.
local function cubicBezierCurvePoint(pointStart,pointMidNear,pointMidFar,pointEnd,alpha)
local Lerp1 = pointStart:Lerp(pointMidNear,alpha)
local Lerp2 = pointMidNear:Lerp(pointMidFar,alpha)
local Lerp3 = pointMidFar:Lerp(pointEnd,alpha)
local Lerp12 = Lerp1:Lerp(Lerp2,alpha)
local Lerp23 = Lerp2:Lerp(Lerp3,alpha)
local LerpFinal = Lerp12:Lerp(Lerp23,alpha)
return LerpFinal
end