Data Realms Fan Forums
http://45.55.195.193/

Glowing Laser Beam Trail
http://45.55.195.193/viewtopic.php?f=75&t=17227
Page 3 of 3

Author:  Geti [ Thu Dec 17, 2009 6:06 am ]
Post subject:  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.

Page 3 of 3 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/