Advertisement
Descaii

Water Simulation

Jul 25th, 2014
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.06 KB | None | 0 0
  1. -- Water 3D[Roblox version] --
  2. Workspace.CurrentCamera:ClearAllChildren()
  3. local Pts = {}
  4. Player = game.Players.LocalPlayer
  5. Mouse = Player:GetMouse()
  6. script.Parent =nil
  7. --S = Instance.new("ScreenGui",Player.PlayerGui)
  8. function NewPoint(SC,X,Y) -- new points
  9.     local P = {}
  10.     P.V = 0 -- up/down velocity
  11.     P.P = #Pts -- up/down height.
  12.     P.LastP = P.P
  13.     P.Part = Instance.new("Part",Workspace.CurrentCamera)
  14.     P.Part.Anchored = true
  15.     P.Part.BrickColor = BrickColor.new("Bright blue")
  16.     P.Part.FormFactor = "Custom"
  17.     P.Button = Instance.new("ClickDetector",P.Part)
  18.     P.Part.TopSurface = "Smooth"
  19.     P.Part.Transparency = 0.5
  20.     P.Part.CanCollide = false
  21.     P.Clicking = false
  22.     P.Button.MouseClick:connect(function()
  23.         P.Clicking = true
  24.         On = false
  25.         local Tip = 0
  26.         local TipM = 800
  27.         local T = Mouse.Hit
  28.         local MDis = 10
  29.         for i,v in pairs(Pts) do
  30.             v.Hax = v.P
  31.         end
  32.         local N = P.P
  33.         repeat wait()
  34.             if Tip < TipM then
  35.                 Tip = Tip+(TipM-Tip)*0.05
  36.                 MDis = MDis +0.01
  37.             end
  38.             for i,v in pairs(Pts) do
  39.                 local r = (v.Part.CFrame.p-T.p).magnitude
  40.                 if r < MDis then
  41.                     v.V = 0
  42.                     v.P = v.Hax+Tip*((MDis-r)/MDis)
  43.                 end
  44.             end
  45.         until not P.Clicking or On
  46.         On = true
  47.         P.Clicking = false
  48.     end)
  49.     P.Button.MouseHoverLeave:connect(function()
  50.         P.Clicking = false
  51.         On = true
  52.     end)
  53.     P.Part.Touched:connect(function(v)
  54.         P.V = P.V +(v.Velocity.magnitude/3)
  55.     end)
  56.     P.X = X
  57.     P.Y = Y
  58.     --P.Gui = Instance.new("TextButton")
  59.     --P.Gui.Size = UDim2.new(0,20,0,20)
  60.     --P.Gui.Parent=SC
  61.     --P.Gui.MouseButton1Click:connect(function()P.P=P.P+100 end)
  62.     --P.Gui.BorderSizePixel=0;P.Gui.Text=''
  63.     table.insert(Pts,P)
  64.     return P
  65. end
  66. SZ = 12
  67. BT = 2
  68. for x = 1,SZ do
  69.     for y = 1,SZ do
  70.         NewPoint(S,x,y)
  71.     end
  72.  end
  73. --[[function love.mousepressed(x,y)
  74.     -- mouse click shet
  75.     for i,v in pairs(Pts) do
  76.         --v.P = math.random(0,100)
  77.         local n = i%(SZ+1)
  78.         local d = math.ceil(i/SZ)
  79.         local n,d = n*40,d*40
  80.         if x > n-29 and y > d-20 and x < n+20 and y < d+20 then
  81.             v.P = v.P+200
  82.         end
  83.         --v.Gui.Position = UDim2.new(0,i*20,0,500);v.Gui.Size=UDim2.new(0,20,0,-(v.P+20))
  84.     end
  85. end]]
  86. local Sp = 0.05 -- FPS Lock.
  87. C = 0 -- dis goes with above
  88. FPS = 0
  89. local N = tick()
  90. local k = 0
  91. On = true
  92. game:GetService("RunService").RenderStepped:connect(function()
  93.     local S = tick()-N
  94.     FPS = S
  95.     C = C + S
  96.     k = k+S
  97.     if C > Sp then
  98.         C = 0
  99.         for i,v in pairs(Pts) do -- hax point lerp
  100.             local P = v
  101.             if On then
  102.                 local B = Pts[i-1]
  103.                 local F = Pts[i+1]
  104.                 local T = Pts[i-(SZ)]
  105.                 local B2 = Pts[i+(SZ)]
  106.                 --[\[
  107.                     if B then
  108.                         v.V = v.V +((B.P-v.P)*0.1) -- add difference between point and point in front to velocity
  109.                     end
  110.                     if F then
  111.                         v.V = v.V +((F.P-v.P)*0.1) -- add difference between point and point behind to velocity
  112.                     end
  113.                     if T then
  114.                         v.V = v.V +((T.P-v.P)*0.1) -- add difference between point and point in front to velocity
  115.                     end
  116.                     if B2 then
  117.                         v.V = v.V +((B2.P-v.P)*0.1) -- add difference between point and point behind to velocity
  118.                     end
  119.                 --]]
  120.                 --[[
  121.                     if B then
  122.                         v.P = v.P+((B.P-v.P)*0.1) -- add difference between point and point in front to velocity
  123.                     end
  124.                     if F then
  125.                         v.P = v.P +((F.P-v.P)*0.1) -- add difference between point and point behind to velocity
  126.                     end
  127.                     if T then
  128.                         v.P = v.P +((T.P-v.P)*0.1) -- add difference between point and point in front to velocity
  129.                     end
  130.                     if B2 then
  131.                         v.P = v.P +((B2.P-v.P)*0.1) -- add difference between point and point behind to velocity
  132.                     end
  133.                 --]]
  134.                 P.P = P.P+(P.P-P.LastP)
  135.                 v.V = v.V*0.89 -- slow down de velocity
  136.                 v.P = v.P +v.V -- add velocity to position
  137.                 v.P = v.P*0.89
  138.                 --v.P = math.abs(v.P)
  139.             end
  140.             -- draw--
  141.             local n = i%(SZ+1)
  142.             local r = math.ceil(i/SZ)*SZ
  143.             local d = math.ceil(r/SZ)
  144.             v.Part.Size = Vector3.new(BT,BT,BT)
  145.             v.Part.CFrame = CFrame.new(v.X*BT,P.P/100+3,v.Y*BT)
  146.             P.LastP = P.P
  147.            
  148.             local n,s = v.X,v.Y
  149.             local d = math.sin(n+(k*5))
  150.             local j = math.sin(s+(k*5))
  151.             v.V = v.V+((d*math.random())+(j*math.random()))
  152.         end
  153.     end
  154.     N = tick()
  155. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement