Re: What does this particle code do?
Numgun wrote:
I'm guessing it draws the particles to the position of self, but how?
what is the local power var for and what exactly is this code doing?
How does it move the said particles and where?
Code:
local power = (50 * (2 + self.Scale));
for particle in MovableMan.Particles do
if particle.PresetName ~= nil and particle.PresetName ~= "Particle Beam Emission Dummy" then
if math.abs(particle.Pos.X - self.Pos.X) < power and math.abs(particle.Pos.Y - self.Pos.Y) < power then
local distVec = self.Pos - particle.Pos;
particle.Vel = particle.Vel + distVec:SetMagnitude(distVec.Magnitude/50);
end
end
end
Heh, a bit late for this, but I'll explain the math anyway.
local power = (50 * (2 + self.Scale));The local variable power, represents the suction power of the accelerator. It determines the radius the suction starts at. When you first start charging the weapon, power is equal to 105 (50 * (2 + 0.1)). At full charge, the radius increases to 175 (50 * (2 + 1.5)).
if math.abs(particle.Pos.X - self.Pos.X) < power and math.abs(particle.Pos.Y - self.Pos.Y) < power thenThis actually could be simplified to: (particle.Pos - self.Pos).Magnitude < power. The engine could would handle the subtraction of individual vector components. math.abs() means "Absolute Value of". Since magnitude is always positive, we need the absolute value.
local distVec = self.Pos - particle.Pos;Just like 5 - 2 will give you the numeric distance between 5 and 2, 'vector a' - 'vector b' will give you a 'vector c' pointing from b to a (or a to b, if you flip them around). The magnitude of c will equal the distance between a and b. [positions can be considered vectors with a starting point at (0,0) and an ending point at the position].
In this case, 'vector c' is distVec. Since distVec points from the particle's position to the orb's position, all we have to do is add this vector to the particle's velocity vector to give it a natural pull effect towards the orb. distVec's magnitude is divided by 50 to scale the the pull down to a speed that isn't retardedly fast (oxymoron?).
particle.Vel = particle.Vel + distVec:SetMagnitude(distVec.Magnitude/50);The end result of all this is: the greater the distance between the particle and the orb, the greater the pull on the particle.