View unanswered posts | View active topics It is currently Thu Dec 26, 2024 6:10 pm



Reply to topic  [ 5 posts ] 
 Advanced Missile Launcher 
Author Message
DRL Developer
DRL Developer
User avatar

Joined: Thu Jun 11, 2009 2:34 pm
Posts: 966
Location: Moscow, Russia
Reply with quote
Post Advanced Missile Launcher
Don't know if spmebody already did this, but I rewrote current missile launcher script so it catch targets at which you aim rather than choosing closest one. If missile can't find target when shot it simply fall with disabled engines. That and increased targeting range (500 -> 750) are the only differences from standard missile launcher. Code is commented so I guess it can serve as an example of CastMORay usage. Currently selected target blinks white for 50 ms.


Attachments:
HomingMissile.rte.zip [3.92 KiB]
Downloaded 212 times
Sun Jul 19, 2009 6:17 pm
Profile
User avatar

Joined: Mon Jun 30, 2008 9:13 pm
Posts: 499
Location: Finland
Reply with quote
Post Re: Advanced Missile Launcher
You could replace this:
Code:
      -- MORay is very accurate so you need to aim carefully to catch something
      -- that's ok with large vessels but it can make harder to hit actors
      -- Thats why we need to make three rays which make 10 degrees scanning ray
      -- first we try direct hit, then +- 5 degrees rays
      local angle = self.parent:GetAimAngle(true);
      local wideangle = {};
      local targetfound = false;

      wideangle[1] = angle;
      wideangle[2] = angle - 0.088; -- Angle in radians
      wideangle[3] = angle + 0.088;
      
      --Start scanning
      for i = 1,3 do
         -- When creating starting point for scanning ray we need it to be outside of firing actor
         -- or CastMORay will detect firing actor and make it target. Targets closer than 90 pixels will
         -- be ignored
         local raystartvector = self.parent.Pos - Vector( -math.cos(wideangle[i]) * 90 , math.sin(wideangle[i]) * 90);
         -- Offset for CastMORay , it don't need to know acrot position, only angles
         -- 750 is the length of scanning ray
         local rayendvector = Vector( math.cos(wideangle[i]) * 750 , - math.sin(wideangle[i]) * 750);
         
         -- Cast ray and get id of MO hit by ray
         local moid = SceneMan:CastMORay(raystartvector , rayendvector , 0 , 0 , false , 3);
         
         -- SceneMan.g_NoMOID returned if we hit ground or hit nothing
         if moid ~= SceneMan.g_NoMOID then
            -- Get MO object from stored id
            local mo = MovableMan:GetMOFromID(moid);

            -- Always check if found object is still alive
            if mo ~= nil then
               -- Find wich actor found MO belong to
               for actor in MovableMan.Actors do
                  if mo.RootID == actor.ID then
                     self.target = actor;
                     self.target:FlashWhite(50);
                     targetfound = true;
                     break;
                  end
               end --for
            end --if
         end --if
         if targetfound then
            break;
         end
      end --for

With this:
Code:
local maxangledifference = 0.088
for actor in MovableMan.Actors do
    local vectortoactor = actor.Pos - self.Pos
    if math.abs(vectortoactor.AbsRadAngle - self.Vel.AbsRadAngle) < macangledifference and vectortoactor.Magnitude < 750 then
      self.target = actor
      maxangledifference = vectortoactor.AbsRadAngle
    end
end
I used that in some version of the Swarmer in Lua guns, though I seem to have lost the script somewhere.
Edit: Forgot the distance check. Added it.


Sun Jul 19, 2009 6:32 pm
Profile
DRL Developer
DRL Developer
User avatar

Joined: Thu Jun 11, 2009 2:34 pm
Posts: 966
Location: Moscow, Russia
Reply with quote
Post Re: Advanced Missile Launcher
Will this compact version check for terrain hits?


Sun Jul 19, 2009 6:47 pm
Profile
User avatar

Joined: Mon Jun 30, 2008 9:13 pm
Posts: 499
Location: Finland
Reply with quote
Post Re: Advanced Missile Launcher
Damn, I knew I forgot something.
Code:
local maxangledifference = 0.088
for actor in MovableMan.Actors do
    local vectortoactor = actor.Pos - self.Pos
    if math.abs(vectortoactor.AbsRadAngle - self.Vel.AbsRadAngle) < macangledifference and vectortoactor.Magnitude < 750 then
      self.calcvel = self.Vel:SetMagnitude(750)
      i = SceneMan:CastMORay(self.Pos,self.calcvel,0,0,false,5)
      self.thingie = MovableMan:GetMOFromID(i)
      if self.thingie ~= nil and self.thingie.RootID ~= actor.ID then
        self.target = actor
        maxangledifference = vectortoactor.AbsRadAngle
      end
    end
end
Edit:Missed an end.


Last edited by piipu on Sun Jul 19, 2009 9:50 pm, edited 1 time in total.



Sun Jul 19, 2009 6:50 pm
Profile
DRL Developer
DRL Developer
User avatar

Joined: Thu Jun 11, 2009 2:34 pm
Posts: 966
Location: Moscow, Russia
Reply with quote
Post Re: Advanced Missile Launcher
Cool, hope somebody will find this before asking :)


Sun Jul 19, 2009 6:58 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.150s | 14 Queries | GZIP : Off ]