View unanswered posts | View active topics It is currently Wed Dec 25, 2024 5:26 pm



Reply to topic  [ 7 posts ] 
 Making Magmaul-derived laser sight stop upon targetting MOID 
Author Message
User avatar

Joined: Sun Oct 29, 2006 4:26 am
Posts: 298
Reply with quote
Post 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!


Fri Nov 30, 2012 8:13 pm
Profile YIM
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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


Sun Dec 02, 2012 11:16 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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.


Mon Dec 03, 2012 1:47 am
Profile
User avatar

Joined: Sun Oct 29, 2006 4:26 am
Posts: 298
Reply with quote
Post 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.


Mon Dec 03, 2012 2:11 pm
Profile YIM
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Making Magmaul-derived laser sight stop upon targetting MOID
Did you try checking if it was equal to 255?


Mon Dec 03, 2012 9:57 pm
Profile
User avatar

Joined: Sun Oct 29, 2006 4:26 am
Posts: 298
Reply with quote
Post 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).


Mon Dec 03, 2012 10:19 pm
Profile YIM
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Making Magmaul-derived laser sight stop upon targetting MOID
Can you post the entire script?


Wed Dec 05, 2012 4:19 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 posts ] 

Who is online

Users browsing this forum: No registered users


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

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.100s | 13 Queries | GZIP : Off ]