|
| 18 Jun 2016 05:40 AM |
So I made a bezier script however I want to know how to make it so that the rotations betweent the parts are smooth. It is an alternative to CFrameing each part individually
--Bezier Function By destructive1ne
--Eqaution to genertate the CFrame of parts corrrosponding to bezier curve function cubicbezier(p0,p1,p2,p3,t) local cf0=p0.CFrame local cf1=p1.CFrame local cf2=p2.CFrame local cf3=p3.CFrame local bx=(1-t)^3*cf0.x+3*(1-t)^2*t*cf1.x+3*(1-t)*t^2*cf2.x+t*cf3.x local by=(1-t)^3*cf0.y+3*(1-t)^2*t*cf1.y+3*(1-t)*t^2*cf2.y+t*cf3.y local bz=(1-t)^3*cf0.z+3*(1-t)^2*t*cf1.z+3*(1-t)*t^2*cf2.z+t*cf3.z return CFrame.new(bx,by,bz) end
-- Creates the parts function t_stuff() for tee=0,1,0.01 do local part=Instance.new("Part") part.Parent=game.Workspace part.Size=Vector3.new(8,2,16) part.Name="bezier_part" part.Anchored=true part.CFrame=cubicbezier(game.Workspace.part0,game.Workspace.part1,game.Workspace.part2,game.Workspace.part3,tee) --However I dont know how to make smooth rotations end end
--This deletes a bezier function deletebezier() for i,v in pairs (game.Workspace:GetChildren()) do if v.Name=="bezier_part" then v:Destroy() end end end
--If any control points of the bezier are moved then the old bezier is deleted and the new --bezier is created t_stuff() game.Workspace.part0.Changed:connect(function (CFrame) deletebezier() t_stuff() end)
game.Workspace.part1.Changed:connect(function (CFrame) deletebezier() t_stuff() end)
game.Workspace.part2.Changed:connect(function (CFrame) deletebezier() t_stuff() end)
game.Workspace.part3.Changed:connect(function (CFrame) deletebezier() t_stuff() end)
|
|
|
| Report Abuse |
|
|
|
| 18 Jun 2016 05:41 AM |
| I also want to know if SLERP is the method and if it is how to do SLERP |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2016 05:45 AM |
| Don't forget to add 4 points and pass them through the cubic bezier function called in t_stuff() |
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 18 Jun 2016 06:19 AM |
Here's an upgrade of your code.
w = game.Workspace parts = {'Part1','Part2','Part3','Part4'} for i,v in pairs(parts) do w:WaitForChild(v) parts[i] = w[v] end currentparts = {}
function cubicbezier(p0,p1,p2,p3,t) local cf0,cf1,cf2,cf3 = p0.CFrame,p1.CFrame,p2.CFrame,p3.CFrame local function xyz(i) return (1-t)^3*cf0[i]+3*(1-t)^2*t*cf1[i]+3*(1-t)*t^2*cf2[i]+t*cf3[i] end return CFrame.new(xyz'x', xyz'y', xyz'z') end
function t_stuff() for tee = 0,1, 0.01 do local part = Instance.new('Part', w) part.Size = Vector3.new(8,2,16) part.Anchored = true part.CFrame = cubicbezier(parts[1], parts[2], parts[3], parts[4], tee) table.insert(currentparts, part) wait() end end
function deletebezier() for i,v in pairs(currentparts) do v:Destroy() end currentparts = {} end
for i,v in pairs(parts) do v.Changed:connect(function (CFrame) deletebezier() t_stuff() end) end
t_stuff() |
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 18 Jun 2016 06:28 AM |
--Small adjustment.
w = game.Workspace parts = {'Part1','Part2','Part3','Part4'} for i,v in pairs(parts) do w:WaitForChild(v) parts[i] = w[v] end currentparts = {}
function cubicbezier(p0,p1,p2,p3,t) local cf0,cf1,cf2,cf3 = p0.CFrame,p1.CFrame,p2.CFrame,p3.CFrame local function xyz(i) return (1-t)^3*cf0[i]+3*(1-t)^2*t*cf1[i]+3*(1-t)*t^2*cf2[i]+t*cf3[i] end return CFrame.new(xyz'x', xyz'y', xyz'z') end
function t_stuff() for tee = 0,1, 0.01 do local part = Instance.new('Part', w) part.Size = Vector3.new(8,2,16) part.Anchored = true part.CFrame = cubicbezier(parts[1], parts[2], parts[3], parts[4], tee) table.insert(currentparts, part) wait() end end
for i,v in pairs(parts) do v.Changed:connect(function() for i,v in pairs(currentparts) do v:Destroy() end currentparts = {} t_stuff() end) end
t_stuff() |
|
|
| Report Abuse |
|
|