Data Realms Fan Forums
http://45.55.195.193/

Making Magmaul-derived laser sight stop upon targetting MOID
http://45.55.195.193/viewtopic.php?f=73&t=33587
Page 1 of 1

Author:  Djinn [ Fri Nov 30, 2012 8:13 pm ]
Post subject:  Making Magmaul-derived laser sight stop upon targetting MOID

This code is influenced heavily by the Magmaul's (Browncoat Gun) targeting dots - in that case it draws an arc, but here I only want it to draw dots in a straight line between the point of emission and the target. I've got it working just fine, except I didn't notice in the initial code that the dots only stop when they hit terrain. What I'm looking for is a way to make it so the dots also stop when they're aimed at an Actor or MOSRotating or whatnot. Also I know the code isn't super efficient use, but I'm just trying to get it working before I clean it up.

Code:
   if self.laserTimer:IsPastSimMS(25) then
      self.laserTimer:Reset();

      for i = 1, #self.particleTable do
         if MovableMan:IsParticle(self.particleTable[i]) then
            self.particleTable[i].ToDelete = true;
         end
      end
      self.particleTable = {};

      self.guideParPos = self.Pos - Vector(-10 , 0):RadRotate(self.RotAngle);
      self.guideParVel = self.Vel - Vector(1 ,40):RadRotate(self.RotAngle);
      for i = 1, self.maxTrajectoryPars do
         if SceneMan:GetTerrMatter(self.guideParPos.X,self.guideParPos.Y) == 0 then
            self.guideParPos = self.guideParPos + self.guideParVel/3;
            local laserParticle = CreateMOPixel("Pop Particle");
            laserParticle.Pos = self.guideParPos;
            MovableMan:AddParticle(laserParticle);
            self.particleTable[#self.particleTable+1] = laserParticle;   
         else
            break;
         end
      end
      
      self.guideParPos = self.Pos - Vector(10 , 0):RadRotate(self.RotAngle);
      self.guideParVel = self.Vel - Vector(-1 ,40):RadRotate(self.RotAngle);
      for i = 1, self.maxTrajectoryPars do
         if SceneMan:GetTerrMatter(self.guideParPos.X,self.guideParPos.Y) == 0 then
            self.guideParPos = self.guideParPos + self.guideParVel/3;
            local laserParticle = CreateMOPixel("Pop Particle");
            laserParticle.Pos = self.guideParPos;
            MovableMan:AddParticle(laserParticle);
            self.particleTable[#self.particleTable+1] = laserParticle;
         else
            break;
         end
      end
   end


tldr; Need a laser sight that takes the distance between two points and places dots along the line in intervals. This method that I'm using 'works', but only ends when it hits terrain instead of anything. Help!

Author:  Grif [ Sun Dec 02, 2012 11:16 pm ]
Post subject:  Re: Making Magmaul-derived laser sight stop upon targetting MOID

You'd have to cast a ray to determine the endpoint, but the rest of that code should be functional. Basically you'd need to replace
Code:
if SceneMan:GetTerrMatter(self.guideParPos.X,self.guideParPos.Y) == 0 then


in both if blocks with a check against the resultant particle from an MORay cast. You should only need to do the raycast once, though you might want to repeat it depending on projectile speed.

Specifically, you need an obstacle ray.

Basically, if you're not 100% on how that code is working, it's generating the particles on a per-frame basis based on the particle's RotAngle, and it's avoiding terrain with the GetTerrMatter check (0 is Air). Replace that check with the equivalent ObstacleRay end value and you won't be able to pass through MOs or terrain

if that didn't make any sense I could theoretically work up better code

Author:  CaveCricket48 [ Mon Dec 03, 2012 1:47 am ]
Post subject:  Re: Making Magmaul-derived laser sight stop upon targetting MOID

It'd be more efficient to use GetMOIDPixel right after GetTerrMatter(), since you only need to check a single pixel.

Author:  Djinn [ Mon Dec 03, 2012 2:11 pm ]
Post subject:  Re: Making Magmaul-derived laser sight stop upon targetting MOID

CaveCricket48 wrote:
It'd be more efficient to use GetMOIDPixel right after GetTerrMatter(), since you only need to check a single pixel.


Yeah, I tried that, but no matter what I set it to equal it didn't seem to make an effect one way or the other on whether the beam was cast.

Author:  CaveCricket48 [ Mon Dec 03, 2012 9:57 pm ]
Post subject:  Re: Making Magmaul-derived laser sight stop upon targetting MOID

Did you try checking if it was equal to 255?

Author:  Djinn [ Mon Dec 03, 2012 10:19 pm ]
Post subject:  Re: Making Magmaul-derived laser sight stop upon targetting MOID

CaveCricket48 wrote:
Did you try checking if it was equal to 255?


Changing it to
Code:
if SceneMan:GetMOIDPixel(self.guideParPos.X,self.guideParPos.Y) == 255 then
does precisely nothing, unfortunately - it doesn't even fire the beam.

Changing it to ~= 255 does something odd, however - the beam only extends two dots out from the emitter, but if a MO crosses its path in that very short range, the beam dots extend over the length of the sprite along the vector the beam is going (if that makes ANY sense at all).

Author:  CaveCricket48 [ Wed Dec 05, 2012 4:19 am ]
Post subject:  Re: Making Magmaul-derived laser sight stop upon targetting MOID

Can you post the entire script?

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