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

How can I do this?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I would love to finish this bezier curve script soon so I can release it to the people i'm making it for, but I am stuck. The position for the bricks generated are okay, but I cannot find a way to make it rotate correctly! Any help? There's no rotation in the script, but that's because I cant find a way to do it, so here's the script if you need it:

bc={}
p1={game.Workspace.Start1.Position,game.Workspace.Cont1.Position,game.Workspace.Start2.Position}
p2={game.Workspace.Start2.Position,game.Workspace.Cont2.Position,game.Workspace.EndStart.Position}
function CreateLerpsP1()
    for i=1,5 do 
        local t = i/5
        bc[i] = p1[1]*(1-t)^2+2*p1[2]*(1-t)*t+p1[3]*t^2
    end
    for i=1,5 do
        local t=Instance.new("Part",workspace.CurTrack)
        t.Name="TrackPoint"
        t.BrickColor=BrickColor.Blue()
        t.Anchored=true
        t.CanCollide=false
        t.Size=Vector3.new(4,1,2)
        t.TopSurface=Enum.SurfaceType.Smooth
        t.BottomSurface=Enum.SurfaceType.Smooth
        if i~=1 then
        t.CFrame=CFrame.new(bc[i]:Lerp(bc[i-1],0.5),bc[i])
        else
        t.CFrame=CFrame.new(bc[i]:Lerp(p1[1],0.5),bc[i])
        end
    end
end

function CreateLerpsP2()
    for i=1,5 do 
        local t = i/5
        bc[i] = p2[1]*(1-t)^2+2*p2[2]*(1-t)*t+p2[3]*t^2
    end
    for i=1,5 do
        local t=Instance.new("Part",workspace.CurTrack)
        t.Name="TrackPoint"
        t.BrickColor=BrickColor.Blue()
        t.Anchored=true
        t.CanCollide=false
        t.Size=Vector3.new(4,1,2)
        t.TopSurface=Enum.SurfaceType.Smooth
        t.BottomSurface=Enum.SurfaceType.Smooth
        if i~=1 then
        t.CFrame=CFrame.new(bc[i]:Lerp(bc[i-1],0.5),bc[i])
        else
        t.CFrame=CFrame.new(bc[i]:Lerp(p2[1],0.5),bc[i])
        end
    end
end
CreateLerpsP1()
CreateLerpsP2()
game.Workspace.Start1.Changed:connect(function() game.Workspace.CurTrack:ClearAllChildren() CreateLerpsP1() CreateLerpsP2() end)
game.Workspace.Cont1.Changed:connect(function() game.Workspace.CurTrack:ClearAllChildren() CreateLerpsP1() CreateLerpsP2() end)
game.Workspace.Start2.Changed:connect(function() game.Workspace.CurTrack:ClearAllChildren() CreateLerpsP1() CreateLerpsP2() end)
game.Workspace.Cont2.Changed:connect(function() game.Workspace.CurTrack:ClearAllChildren() CreateLerpsP2() CreateLerpsP1() end)
game.Workspace.EndStart.Changed:connect(function() game.Workspace.CurTrack:ClearAllChildren() CreateLerpsP2() CreateLerpsP1() end)

Answer this question