Particle check causing momentary freeze *fixed*
Uhh, yeah. That probably didn't make sense. Anyways, i've made a script which acts like a gravitational singularity (pulls stuff in), but if i also make it affect particles, the game locks up for a second or two, after which the projectile never appears. If it was fired near terrain, some particles get launched with a scary speed. Here's the abridged script that causes it:
Code:
function Create(self)
self.pullRadius = 100;
self.maxPull = 100;
end
function Update(self)
for target in MovableMan.Particles do
if target:IsAtRest() == false then
if target.PresetName ~= "SGYCAN Gravitation Weak" and target.PresetName ~= "SGYCAN Glow Effect" then
local targetVector = SceneMan:ShortestDistance(self.Pos, target.Pos, true);
if targetVector.Magnitude < self.pullRadius then
local angle = math.atan2(-targetVector.Y, targetVector.X);
target.Vel = target.Vel + Vector((-self.maxPull*(1/targetVector.Magnitude)),0):RadRotate(angle);
end
end
end
end
end
I'm thinking that it somehow also checks the terrain, but if it does that, why haven't i seen this phenomenon before? The reflective robot i made (second iteration) checks for particles too, and it doesn't cause any lockups whatsoever. Any idea of why this happens?
Edit: Setting it to check for PinStrength == 0 reduces the lockup time, but it still happens. Argh.
Edit 2: argh crud, i never expected it to include itself in the particle check. In other words, making sure that the particle in question isn't itself fixes the problem entirely. Sorry about wasting space. :U