Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local module = {}
- local ratio = math.sqrt(3) / math.sqrt(2)
- local e = 50 * ratio
- local f = 1000 * ratio
- function module:newParticle(x, y, z, mass, radius, locked)
- local newparticle = {}
- newparticle.pos = Vector3.new(x, y, z)
- newparticle.vel = Vector3.new()
- newparticle.acc = Vector3.new()
- newparticle.mass = mass
- newparticle.particle = Instance.new("SpawnLocation", script)
- newparticle.particle.Anchored = true
- newparticle.particle.Enabled = false
- newparticle.particle.Position = newparticle.pos
- newparticle.particle.Shape = "Ball"
- newparticle.particle.Size = Vector3.new(radius*2, radius*2, radius*2)
- newparticle.particle.Transparency = 1
- function newparticle:applyForce(force)
- local applied_force = force/self.mass
- self.acc += applied_force
- end
- function newparticle:grav(other)
- local dvector = self.pos - other.pos
- local distance = dvector.Magnitude
- local dsquared = math.clamp(distance*distance, e, f)
- local g = 5
- local GForcebot = g*self.mass*other.mass/dsquared -- lo
- dvector = dvector * (1/dvector.Magnitude) * GForcebot
- other:applyForce(dvector)
- end
- function newparticle:updateMovements(other)
- if not self.locked then
- self:grav(other)
- self.vel += self.acc
- self.pos += self.vel
- self.particle.Position = self.pos
- self.acc = Vector3.new()
- else
- self:grav(other)
- end
- end
- function newparticle:visualize()
- self.particle.Transparency = 0
- end
- return newparticle
- end
- return module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement