Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Bezier curve changes rotation midway the curve?

Asked by 4 years ago
Edited 4 years ago

This bezier curve seems to be not synced rotation wise midway. I am looking for a solution. Here's what it looks like.

Bezier Curve

What I'm looking for in the image link below is the black but what I don't want is in red.

Feel free to test it out by inserting this script into workspace.

local orig = Instance.new("Part")
orig.Position = workspace.Baseplate.Position + Vector3.new(0,20,0)
orig.CFrame = orig.CFrame * CFrame.Angles(0,math.rad(45),0)
local pos1 = Instance.new("Part")
pos1.CFrame = orig.CFrame 
local pos2 = Instance.new("Part")
pos2.CFrame = pos1.CFrame * CFrame.new(0,11,-35)
local pos3 = Instance.new("Part")
pos3.CFrame = pos1.CFrame * CFrame.new(0,150,-10)

orig.Anchored = true
pos1.Anchored = true
pos2.Anchored = true
pos3.Anchored = true

orig.Size = Vector3.new(1,1,1)
pos1.Size = Vector3.new(1,1,1)        
pos2.Size = Vector3.new(1,1,1)        
pos3.Size = Vector3.new(1,1,1)        

orig.Parent = workspace
pos1.Parent = workspace
pos2.Parent =workspace
pos3.Parent = workspace

local function Lerp(a, b, c)
        return a + (b - a) * c
    end
local function quadBezier(t, p0, p1, p2)
    local l1 = Lerp(p0, p1, t)
    local l2 = Lerp(p1, p2, t)
    local quad = Lerp(l1, l2, t)

    return quad
end

for i = 0,1+.01,1/21 do
    local posb = quadBezier(i,pos1.Position,pos2.Position,pos3.Position)
    local posb1 = quadBezier(i+(1/21),pos1.Position,pos2.Position,pos3.Position)
    local a = Instance.new('Part')
    a.Size = Vector3.new(1,1,1)
    a.Anchored = true
    a.Parent = script.Parent
    a.CFrame = CFrame.new(posb,posb1)
end

Answer this question