Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {Players, RunService, Workspace} from "@rbxts/services";
- //Classes
- class Particle{
- object: Frame;
- x_pos: number
- y_pos : number;
- prev_ypos: number;
- prev_xpos: number;
- bounce = 0.9;
- gravity = 0.4;
- constructor(Parent: undefined | Instance){
- this.object = new Instance("Frame");
- this.object.Parent = Parent;
- this.object.Size = new UDim2(new UDim(0, 10), new UDim(0, 10));
- this.object.BackgroundColor3 = new Color3(0, 0, 0);
- this.x_pos = 10;
- this.y_pos = 10;
- this.prev_xpos = 0;
- this.prev_ypos = 0;
- }
- updatePoint(){
- let vx = (this.x_pos - this.prev_xpos);
- let vy = (this.y_pos - this.prev_ypos);
- this.prev_xpos = this.x_pos;
- this.prev_ypos = this.y_pos;
- this.x_pos += vx;
- this.y_pos += vy;
- this.y_pos += this.gravity;
- if(this.x_pos > VIEWPORT_SIZE.X){
- this.x_pos = VIEWPORT_SIZE.X;
- this.prev_xpos = this.x_pos + (vx*this.bounce);
- }else if(this.x_pos < 1/60){
- this.prev_xpos = this.x_pos + (vx*this.bounce);
- }
- if (this.y_pos > VIEWPORT_SIZE.Y){
- this.y_pos = VIEWPORT_SIZE.Y ;
- this.prev_ypos = this.y_pos + (vy*this.bounce);
- }else if(this.y_pos < 1/60) {
- this.prev_ypos = this.y_pos + (vy*this.bounce);
- }
- }
- registerPont(){
- this.object.Position = new UDim2(new UDim(0, this.x_pos), new UDim(0, this.y_pos));
- }
- }
- //Objects
- let player = Players.LocalPlayer;
- let camera = Workspace.CurrentCamera;
- let main_ui: ScreenGui | undefined = player.WaitForChild("PlayerGui").WaitForChild<ScreenGui>("Main");
- let frame: Instance | undefined = main_ui!.FindFirstChild("Frame");
- let particle = new Particle(frame);
- //Constants
- const VIEWPORT_SIZE = camera!.ViewportSize;
- //Functions
- function update(){
- particle.updatePoint();
- particle.registerPont();
- }
- function sortOrderIn(Object: Instance[]){
- Object.forEach((element, index, array) => {
- element.Name = `Particle_${index+1}`;
- });
- }
- //Events
- RunService.RenderStepped.Connect(update);
- sortOrderIn(frame!.GetChildren());
- export {};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement