Advertisement
Guest User

Particle Physics made by Syharaa (Lua Version)

a guest
Dec 12th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.43 KB | None | 0 0
  1. -- Compiled with https://roblox-ts.github.io v0.2.14
  2. -- November 9, 2019, 7:14 PM Bolivia Time
  3.  
  4. local TS = require(game:GetService("ReplicatedStorage"):WaitForChild("rbxts_include"):WaitForChild("RuntimeLib"));
  5. local VIEWPORT_SIZE;
  6. local _0 = TS.import(TS.getModule("services"));
  7. local Players, RunService, Workspace = _0.Players, _0.RunService, _0.Workspace;
  8. local Particle;
  9. do
  10.     Particle = setmetatable({}, {
  11.         __tostring = function() return "Particle" end;
  12.     });
  13.     Particle.__index = Particle;
  14.     function Particle.new(...)
  15.         local self = setmetatable({}, Particle);
  16.         self:constructor(...);
  17.         return self;
  18.     end;
  19.     function Particle:constructor(Parent)
  20.         self.bounce = 0.9;
  21.         self.gravity = 0.4;
  22.         self.object = Instance.new("Frame");
  23.         self.object.Parent = Parent;
  24.         self.object.Size = UDim2.new(UDim.new(0, 10), UDim.new(0, 10));
  25.         self.object.BackgroundColor3 = Color3.new(0, 0, 0);
  26.         self.x_pos = 10;
  27.         self.y_pos = 10;
  28.         self.prev_xpos = 0;
  29.         self.prev_ypos = 0;
  30.     end;
  31.     function Particle:updatePoint()
  32.         local vx = self.x_pos - self.prev_xpos;
  33.         local vy = self.y_pos - self.prev_ypos;
  34.         self.prev_xpos = self.x_pos;
  35.         self.prev_ypos = self.y_pos;
  36.         self.x_pos = self.x_pos + (vx);
  37.         self.y_pos = self.y_pos + (vy);
  38.         self.y_pos = self.y_pos + (self.gravity);
  39.         if self.x_pos > VIEWPORT_SIZE.X then
  40.             self.x_pos = VIEWPORT_SIZE.X;
  41.             self.prev_xpos = self.x_pos + (vx * self.bounce);
  42.         elseif self.x_pos < 1 / 60 then
  43.             self.prev_xpos = self.x_pos + (vx * self.bounce);
  44.         end;
  45.         if self.y_pos > VIEWPORT_SIZE.Y then
  46.             self.y_pos = VIEWPORT_SIZE.Y;
  47.             self.prev_ypos = self.y_pos + (vy * self.bounce);
  48.         elseif self.y_pos < 1 / 60 then
  49.             self.prev_ypos = self.y_pos + (vy * self.bounce);
  50.         end;
  51.     end;
  52.     function Particle:registerPont()
  53.         self.object.Position = UDim2.new(UDim.new(0, self.x_pos), UDim.new(0, self.y_pos));
  54.     end;
  55. end;
  56. local player = Players.LocalPlayer;
  57. local camera = Workspace.CurrentCamera;
  58. local main_ui = player:WaitForChild("PlayerGui"):WaitForChild("Main");
  59. local frame = main_ui:FindFirstChild("Frame");
  60. local particle = Particle.new(frame);
  61. VIEWPORT_SIZE = camera.ViewportSize;
  62. local function update()
  63.     particle:updatePoint();
  64.     particle:registerPont();
  65. end;
  66. local function sortOrderIn(Object)
  67.     TS.array_forEach(Object, function(element, index, array)
  68.         element.Name = "Particle_" .. tostring(index + 1);
  69.     end);
  70. end;
  71. RunService.RenderStepped:Connect(update);
  72. sortOrderIn(frame:GetChildren());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement