Sup peeps. I’m making this shuttle that moves sinusoidally on the XZ plane, which tilts towards more as it reaches the sides of the curve. I thought I had it working fine (first part of video) but for some orientations it breaks (second part of video) and I don’t know why ![]()
local shuttle = script.Parent
local mesh = shuttle.ShuttleMesh
local lookVector = mesh.CFrame.LookVector
local rightVector = mesh.CFrame.RightVector
local TS = game:GetService("TweenService")
local RS = game:GetService("RunService")
local SF = 5
local STRETCH = 0.4
local SPEED = 1
local x = 0
local relativeOrigin = shuttle.PrimaryPart.Position
local oldSet = relativeOrigin + x*lookVector*STRETCH + math.sin(math.rad(x))*rightVector*SF
RS.Heartbeat:Connect(function()
x += 1*SPEED
local sin = math.sin(math.rad(x)) print(sin)
local setX = relativeOrigin + x*lookVector*STRETCH
local newSet = setX + sin*rightVector*SF
local dVec3 = oldSet - newSet
local dCentre = newSet - setX
local calculateTilt = -(dCentre/rightVector).Z
shuttle:SetPrimaryPartCFrame(CFrame.new(newSet))
local c = {shuttle.PrimaryPart.CFrame:GetComponents()}
local lookat = CFrame.new(shuttle.PrimaryPart.Position,shuttle.PrimaryPart.Position + dVec3*30)
local c2 = {lookat:GetComponents()}
local r00,r02,r20,r22 = c2[4],c2[6],c2[10],c[12]
shuttle:SetPrimaryPartCFrame(CFrame.new(c[1],c[2],c[3],r00,c[5],r02,c[7],c[8],c[9],r20,c[11],r22))
shuttle:SetPrimaryPartCFrame(shuttle.PrimaryPart.CFrame * CFrame.Angles(0,0,math.rad(calculateTilt*10)))
oldSet = newSet
end)