View unanswered posts | View active topics It is currently Thu Dec 26, 2024 5:33 pm



Reply to topic  [ 7 posts ] 
 Need help on magnetism effect. 
Author Message
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Need help on magnetism effect.
You could have something like
Code:
self.magneticStrength = 0.5;
local dist = SceneMan:ShortestDistance(self.Pos,self.target.Pos,true);
self.target.Vel = self.target.Vel + dist:SetMagnitude(self.magneticStrength^dist.Magnitude);

Since magnetic strength decreases exponentially over distance.


Mon May 09, 2011 1:27 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Need help on magnetism effect.
My bit of code was just a snippet. But yeah, PresetName check would do it.


Mon May 09, 2011 2:11 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Need help on magnetism effect.
Yeah, but you could condense it a bit, and optimize. (And change the actual variables to match up). And BTW, one (=) to set a value, two (==) to check.
Code:
   self.magneticStrength = 0.5;

   for particle in MovableMan.Particle do
      if particle.PresetName == self.PresetName then
         local dist = SceneMan:ShortestDistance(self.Pos,particle.Pos,true);
         if dist.Magnitude < 5 then
               particle.Vel = self.target.Vel + dist:SetMagnitude(self.magneticStrength^dist.Magnitude);
         end
      end
   end

Dump the "self.magneticStrength = 0.5" in function Create(), don't leave it in Update().


Mon May 09, 2011 3:54 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Need help on magnetism effect.
Can I see your complete script?


Mon May 09, 2011 10:58 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Need help on magnetism effect.
Change line 24 to this:
Code:
                if particle.PresetName ~= nil and particle.PresetName == self.PresetName then


Mon May 09, 2011 11:40 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Need help on magnetism effect.
Well THERE'S the problem. You're supposed to change all "self.target" to the pointer you're using for the particle silly ("particle").


Mon May 09, 2011 11:58 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Need help on magnetism effect.
That is correct.


Tue May 10, 2011 1:21 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 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.069s | 13 Queries | GZIP : Off ]