Data Realms Fan Forums http://45.55.195.193/ |
|
Need help on magnetism effect. http://45.55.195.193/viewtopic.php?f=73&t=23643 |
Page 1 of 1 |
Author: | CaveCricket48 [ Mon May 09, 2011 1:27 am ] |
Post subject: | 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. |
Author: | CaveCricket48 [ Mon May 09, 2011 2:11 am ] |
Post subject: | Re: Need help on magnetism effect. |
My bit of code was just a snippet. But yeah, PresetName check would do it. |
Author: | CaveCricket48 [ Mon May 09, 2011 3:54 am ] |
Post subject: | 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(). |
Author: | CaveCricket48 [ Mon May 09, 2011 10:58 pm ] |
Post subject: | Re: Need help on magnetism effect. |
Can I see your complete script? |
Author: | CaveCricket48 [ Mon May 09, 2011 11:40 pm ] |
Post subject: | Re: Need help on magnetism effect. |
Change line 24 to this: Code: if particle.PresetName ~= nil and particle.PresetName == self.PresetName then |
Author: | CaveCricket48 [ Mon May 09, 2011 11:58 pm ] |
Post subject: | 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"). |
Author: | CaveCricket48 [ Tue May 10, 2011 1:21 am ] |
Post subject: | Re: Need help on magnetism effect. |
That is correct. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |