Hello guys. I’m making game, where I need to utilize bezier curves. And, at some point, I came to point where I need offset orbs from ship’s back part by 2 studs. How I can do that?
Ship fly formula:
local CurDot = CreateCurve(ShipPoints, "Dot", CurTime / AnimTime)
local ShipCFrame = CFrame.new(CurDot.X, CurDot.Y, CurDot.Z)
if PrevDot then
ShipCFrame = lookAt2(PrevDot, CurDot) * CFrame.Angles(-math.pi/2, math.pi / 2, 0)
end
Spaceship:PivotTo(ShipCFrame)
Create curve / bezier:
local function CreateCurve(Dots, Mode, Value)
if Mode == "Length" then
local BezierCurve = {}
for i = 0, 100, 1 do
local Lerps = table.clone(Dots)
while #Lerps > 1 do
for a = 1, #Lerps-1, 1 do
Lerps[a] = Vector3.new(Lerps[a].X * (1 - i/100) + Lerps[a+1].X * i/100, 0, Lerps[a].Z * (1 - i/100) + Lerps[a+1].Z * i/100)
end
Lerps[#Lerps] = nil
end
table.insert(BezierCurve, Lerps[1])
end
local BezierLength = 0
for i = 1, #BezierCurve - 1, 1 do
BezierLength += (BezierCurve[i + 1] - BezierCurve[i]).Magnitude
end
return BezierLength
elseif Mode == "Dot" then
local BezierCurve = {}
local Lerps = table.clone(Dots)
while #Lerps > 1 do
for a = 1, #Lerps-1, 1 do
Lerps[a] = Vector3.new(Lerps[a].X * (1 - Value) + Lerps[a+1].X * Value, 0, Lerps[a].Z * (1 - Value) + Lerps[a+1].Z * Value)
end
Lerps[#Lerps] = nil
end
return Lerps[1]
end
end
So, ship is flying on bezier, counting each position independently on others.