View unanswered posts | View active topics It is currently Sat Apr 20, 2024 2:08 am



Reply to topic  [ 5 posts ] 
 What does this particle code do? 
Author Message

Joined: Sat Jan 13, 2007 11:04 pm
Posts: 2932
Reply with quote
Post What does this particle code do?
I'm cutting up the particle accelerators code into pieces to try make a more stable and better version of it and after looking at some of the Lua nuclear scientist code, I ran into this part:

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


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?


Fri Jun 19, 2009 3:30 pm
Profile
User avatar

Joined: Wed Jan 07, 2009 10:26 am
Posts: 4074
Location: That quaint little British colony down south
Reply with quote
Post Re: What does this particle code do?
Code:
         local power = (50 * (2 + self.Scale));--Has the power of pull increase as the ball grows larger.
         for particle in MovableMan.Particles do
            if particle.PresetName ~= nil and particle.PresetName ~= "Particle Beam Emission Dummy"  then --As long as the particle exists and isn't a presumably effect particle
               if math.abs(particle.Pos.X - self.Pos.X) < power and math.abs(particle.Pos.Y - self.Pos.Y) < power then --As long as particle is within square centred on orb or possibly radius, I don't know what math.abs does
                  local distVec = self.Pos - particle.Pos; --Makes a new vector of the difference in position between the orb and the affected particle
                  particle.Vel = particle.Vel + distVec:SetMagnitude(distVec.Magnitude/50); --Add the above defined vector divided by 50 to the particle's velocity, propelling it in the orb's direction.
               end
            end
         end


Fri Jun 19, 2009 3:39 pm
Profile WWW

Joined: Sat Jan 13, 2007 11:04 pm
Posts: 2932
Reply with quote
Post Re: What does this particle code do?
Thanks alot, now I think I got it now. :smile:
This code was pretty much like the gravitation code piipu used in his lua guns except this also included the scale increase that would increase the radius...

sweet.


Fri Jun 19, 2009 3:48 pm
Profile

Joined: Sat Feb 03, 2007 7:11 pm
Posts: 1496
Reply with quote
Post Re: What does this particle code do?
If only it did draw something.

Then we could get our Draw Functions to work, and it would be great.


Fri Jun 19, 2009 4:04 pm
Profile WWW
User avatar

Joined: Sun May 31, 2009 1:04 am
Posts: 308
Reply with quote
Post 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 then
This 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.


Sun Jun 21, 2009 12:39 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.086s | 15 Queries | GZIP : Off ]