Re: Glowing Laser Beam Trail
it was a syntax error and it trying to use the other method when oldpos was equal to self.Pos.
anyway, fixed.
Code:
function Create(self)
self.oldpos = Vector(self.Pos.X, self.Pos.Y)
self.numberofdivisions = math.random(10,16)
for i = 1, self.numberofdivisions do
local particle = CreateMOPixel("SuperLaser Trail Glow", "BOX.rte")
particle.Pos = self.Pos - ((self.Vel * (TimerMan.DeltaTimeSecs * FrameMan.PPM)) * (i/ (self.numberofdivisions)))
MovableMan:AddParticle(particle)
end
for i = 1, self.numberofdivisions do
local particle = CreateMOPixel("SuperLaser Trail Glow", "BOX.rte")
particle.Pos = self.Pos + ((self.Vel * (TimerMan.DeltaTimeSecs * FrameMan.PPM)) * (i/ (self.numberofdivisions)))
MovableMan:AddParticle(particle)
end
local particle = CreateMOPixel("SuperLaser Trail Glow", "BOX.rte")
particle.Pos = self.Pos
MovableMan:AddParticle(particle)
end
function Update(self)
if self.Age > TimerMan.DeltaTimeMS * 1.5 then
self.numberofdivisions = math.random(10,16)
for i = 1, self.numberofdivisions do
local particle = CreateMOPixel("SuperLaser Trail Glow", "BOX.rte")
particle.Pos = self.Pos - (SceneMan:ShortestDistance(self.Pos,self.oldpos,true) * (i / self.numberofdivisions))
MovableMan:AddParticle(particle)
end
end
self.oldpos = Vector(self.Pos.X, self.Pos.Y) --set the old position again
end
Keep in mind that this method is flawed in its process, as you'll notice sometimes where the trail hits there will be a line into the terrain. You should essentially be using rays and getting rid of the dependence on particles altogether. But whatever, it'll work. enjoy.