Joined: Fri May 15, 2009 10:29 am Posts: 4107 Location: Russia
Re: Lagless continuous laser
Because that lags like hell?
Wed Jun 13, 2012 8:08 pm
xenoargh
Joined: Fri Dec 30, 2011 3:33 am Posts: 276
Re: Lagless continuous laser
I'm not being clear, my apologies.
Every 100 pixels, create new sprite object at the offset.
I'll look at the script and see what's up. That seems needless.
[EDIT]
OK, so glows.ini makes reference to 999 BMP files. Why not just keep referring to the first?
I'll fix that and see what's up with CastObstacleRay; wanted to test that.
[/EDIT]
Wed Jun 13, 2012 8:19 pm
xenoargh
Joined: Fri Dec 30, 2011 3:33 am Posts: 276
Re: Lagless continuous laser
Got most of it working already, and the extra bitmaps aren't necessary, but haven't fixed the angle for the beam segments yet, I'm still trying to figure out what's connected to what. Here's a working B27 script:
Code:
function CreateLaserParticle(angle,x,y) local nbr = 1000; local apn = 3.14159265358979323846/nbr; local an = angle; if an < 0 then an = an + 3.14159265358979323846; end local n = math.ceil(an/apn); if n > nbr-1 then n = nbr-1; end local i = CreateMOPixel("MHGLPR"..n); i.Pos = Vector(x,y); MovableMan:AddMO(i); end
function CreateLaserParticleShort(angle,x,y) local nbr = 248; local apn = 3.14159265358979323846/nbr; local an = angle; if an < 0 then an = an + 3.14159265358979323846; end local n = math.ceil(an/apn); if n > nbr-1 then n = nbr-1; end local i = CreateMOPixel("MHGLPRSH"..n); i.Pos = Vector(x,y); MovableMan:AddMO(i); end
function Create(self) self.Offset = 104; self.Offset2 = 13; self.Offset3 = 1; self.Range = 1000; self.Vibrations = 0.005; --/1000 rad end
function Destroy(self) end
function Update(self) local m = SceneMan:ShortestDistance(self.Pos, self.MuzzlePos, true); local an = math.atan2(m.Y,m.X)+math.random(-1000,1000)*0.001*self.Vibrations; local mo = Vector(m.Magnitude*math.cos(an),m.Magnitude*math.sin(an)); local anan = math.atan2(mo.Y,mo.X); if self:IsActivated() then local p = Vector(); local ray =
ed.Y*dist); dist = dist+self.Offset2; end dist = dist-self.Offset2/2+self.Offset3/2; while dist <= ray+24 do local i = CreateMOPixel("MHGLPR-1"); i.Pos = self.MuzzlePos+mo.Normalized*dist; MovableMan:AddMO(i); dist = dist+self.Offset3; end --
CreateLaserParticle(anan,p.X-mo.Normalized.X*self.Offset/2,p.Y-mo.Normalized.Y*self.Offset/2); i = CreateMOPixel("MHGLPR-2"); i.Pos = p; MovableMan:AddMO(i); i = CreateMOPixel("LRB2"); i.Pos = p; local th = math.random(-1000,1000)*0.001; local v = math.random(0,25); i.Vel = Vector(v*math.cos(th),v*math.sin(th)); MovableMan:AddMO(i);
end
end
Wed Jun 13, 2012 8:50 pm
xenoargh
Joined: Fri Dec 30, 2011 3:33 am Posts: 276
Re: Lagless continuous laser
OK, here's a working lagless laser that can be used continuously if you want.
The version I've coded up here is not a continuous beam, but uses discrete shots.
Why? Because a truly continuous laser would be pretty game-breaking in terms of balance, imho, and I really don't see how you can make it lagless and still have a decent visual effect, if you're going to allow it to fade over a few gameframes, due to alpha testing.
But you can make it that way without serious problems.
File size is down to 4K, code's simpler and probably can get even simpler than this did; I added a few visual bells and whistles for the heck of it. The laser, like Mehman's original design, will not tear up terrain. Credit to Azukki and Mehman for being pioneers in this area and providing source
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