Advertisement
minimic2002

Roblox Curve Script

Jun 19th, 2020
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. --Minis Curve Creating Script (UnderDev)
  2. --https://developer.roblox.com/en-us/articles/Bezier-curves
  3. -- T is a decimal below 1, 1 means curve is completed
  4. --So smaller intervals means more points and smoother creation
  5. --P1 Is midpoint
  6. --P0 and P2 are the start and finish
  7. --Uses Pythag and current position + %Complete
  8. --V1
  9. function lerp(a,b,c)
  10. return a + (b - a) * c
  11. end
  12.  
  13. --Lerps All the points
  14. function CurvePoint(p0,p1,p2,t)
  15. t = t
  16. --LERP X
  17. Xl1 = lerp(p0.X, p1.X, t)
  18. Xl2 = lerp(p1.X, p2.X, t)
  19. XLerp = lerp(Xl1, Xl2, t)
  20. --LERP Y
  21. Yl1 = lerp(p0.Y, p1.Y, t)
  22. Yl2 = lerp(p1.Y, p2.Y, t)
  23. YLerp = lerp(Yl1, Yl2, t)
  24. --LERP Z
  25. Zl1 = lerp(p0.Z, p1.Z, t)
  26. Zl2 = lerp(p1.Z, p2.Z, t)
  27. ZLerp = lerp(Zl1, Zl2, t)
  28.  
  29. Pos = Vector3.new(XLerp,YLerp,ZLerp)
  30.  
  31. return Pos
  32. end
  33.  
  34. -- Simplify Curve
  35. -- T should usually be 0
  36. function CreateCurve(p0,p1,p2,t,Inc)
  37. Points = {}
  38. t = t
  39. LoopCount = 0
  40. while t < 0.99 do
  41. CurvePoint(p0,p1,p2,t)
  42. Points[LoopCount] = CurvePoint(p0,p1,p2,t)
  43. --Keeps Track Of Progress
  44. LoopCount = LoopCount + 1
  45. t = LoopCount * Inc
  46. end
  47. return Points
  48. end
  49.  
  50. function test()
  51. print("test")
  52. p0 = game.Workspace.p0.Position
  53. p1 = game.Workspace.p1.Position
  54. p2 = game.Workspace.p2.Position
  55. t = 0
  56. Inc = 0.02
  57. Curve = CreateCurve(p0,p1,p2,t,Inc)
  58. for i = 1,#Curve do
  59. Point = Curve[i]
  60. NewPart = Instance.new("Part",game.Workspace.Test)
  61. NewPart.Size = Vector3.new(1,1,1)
  62. NewPart.Transparency = 0.5
  63. NewPart.Anchored = true
  64. NewPart.Position = Point
  65. wait(0.1)
  66. end
  67. end
  68. test()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement