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



Reply to topic  [ 12 posts ] 
 Request: Homing missile ignoring peeps behind terrain 
Author Message
User avatar

Joined: Tue Apr 01, 2008 4:49 pm
Posts: 1972
Location: The Netherlands
Reply with quote
Post Request: Homing missile ignoring peeps behind terrain
Helloes,

I am using a slightly altered homing missile script from a couple builds back, then used by the coalition missile launcher.

It mostly does the job, except that it sees enemies through terrain and thus missiles often smack right into the ground because someone's hiding down below.

I am wondering if this script could be altered somehow (with morays? :???: ), so missiles avoid going after an enemy hiding behind terrain?

Could anyone take a look at this? :)

The script:
Attachment:
HM.rar [1021 Bytes]
Downloaded 336 times


Mon Jul 09, 2012 10:03 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post Re: Request: Homing missile ignoring peeps behind terrain
This is the same line of code I gave to 4zk not long ago, I still don't know if it works.
Code:
function Create(self)
--The timer that will measure out the missile's events.
    self.LTimer = Timer();

--The delay timer at the start
   self.DelayTimer = Timer();
   self.DelayInterval = 500;
   self.DelayTimer:Reset();

--The missile's target, currently set to nothing.

    self.target = nil;

--Find out who shot the weapon by finding the closest actor within 50 pixels.
    local curdist = 50;
    for actor in MovableMan.Actors do
   local avgx = actor.Pos.X - self.Pos.X;
   local avgy = actor.Pos.Y - self.Pos.Y;
   local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
   if dist < curdist and actor.ClassName ~= "ADoor" then
       if SceneMan:CastFindMORay(self.Pos, actor.Pos, actor.RootID, Vector(), 0, false, 1) = true then
          curdist = dist;
          self.parent = actor;
       end
   end
    end

--If the missile has no firer, make it go after anyone.  Otherwise, set its team to that of the firer.
    if MovableMan:IsActor(self.parent) then
   self.Team = self.parent.Team;
    else
   self.Team = -1;
    end
end

function Update(self)
if self.DelayTimer:IsPastSimMS(self.DelayInterval) then
    if self.LTimer:IsPastSimMS(250) or MovableMan:IsActor(self.target) == false then
   --Get a target.  Go for the closest actor within 500 pixels.
   if MovableMan:IsActor(self.target) == false then
       local curdist = 500;
       for actor in MovableMan.Actors do
      local avgx = actor.Pos.X - self.Pos.X;
      local avgy = actor.Pos.Y - self.Pos.Y;
      local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
      if dist < curdist and actor.Team ~= self.Team and actor.ClassName ~= "ADoor" then
          if SceneMan:CastFindMORay(self.Pos, actor.Pos, actor.RootID, Vector(), 0, false, 1) = true then
             curdist = dist;
             self.target = actor;
          end
      end
       end
   end

   --If the target still exists...
   if MovableMan:IsActor(self.target) then

       --Make sure the missile's thruster is firing.
       if self:IsEmitting() == false then
           self:EnableEmission(true);
       end

       local turnspeed = 0.5;
       local maxspeed = 30;
      
       local targetdir = math.atan2(-(self.target.Pos.Y-self.Pos.Y),(self.target.Pos.X-self.Pos.X));
       local desiredspeedx = math.cos(targetdir) * maxspeed
       local desiredspeedy = math.sin(targetdir) * (-maxspeed)
      
       if self.Vel.X < desiredspeedx then
          self.Vel.X = self.Vel.X + turnspeed
       elseif self.Vel.X > desiredspeedx then
          self.Vel.X = self.Vel.X - turnspeed
       end
       if self.Vel.Y < desiredspeedy then
          self.Vel.Y = self.Vel.Y + turnspeed
       elseif self.Vel.Y > desiredspeedy then
          self.Vel.Y = self.Vel.Y - turnspeed
       end
      
   else
       --If there's no target, shut off the thrusters.
       if self:IsEmitting() == true then
           self:EnableEmission(false);
       end
   end

   if self.LTimer:IsPastSimMS(5000) then
       --If the missile has run out of time, self destruct!
       self:GibThis();
   end
    end
else
    --Make sure the missile's thruster is firing.
    if self:IsEmitting() == false then
        self:EnableEmission(true);
    end
end
end


Mon Jul 09, 2012 10:33 pm
Profile
User avatar

Joined: Tue Apr 01, 2008 4:49 pm
Posts: 1972
Location: The Netherlands
Reply with quote
Post Re: Request: Homing missile ignoring peeps behind terrain
Thanks for that!
A question though, it gives the error
Code:
ERROR: UniTec.rte/Devices/Lua/Homing Missile.lua:21: 'then' expected near '='

Interestingly line 47 does not give this error. :???:


Mon Jul 09, 2012 11:34 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post Re: Request: Homing missile ignoring peeps behind terrain
MY BAD.


Mon Jul 09, 2012 11:53 pm
Profile
User avatar

Joined: Tue Apr 01, 2008 4:49 pm
Posts: 1972
Location: The Netherlands
Reply with quote
Post Re: Request: Homing missile ignoring peeps behind terrain
Thanks! This works like a charm, almost... Gawd, with new functionality comes new problems.

The missile doesn't check for a new target. Once it fires and there's nothing at that particular moment in its line of sight it'll just go straight forward, even when a target might come up during its flight.
It makes it impossible, for example, to fire over a hilltop and have the missile go after something behind the hill.

Attachment:
missile.png
missile.png [ 2.7 KiB | Viewed 7463 times ]

Would this be possible?
I'd guess some sort of continuous check would create lag the size of New York, so maybe it's possible to do such a check every half second or so? :???:

Thanks for your help so far. I really appreciate it. :)


Tue Jul 10, 2012 12:50 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Request: Homing missile ignoring peeps behind terrain
Here, give these a try. Heavily cut-down from the GML script to the point where they're extremely basic.

MissileA.lua uses the same experimental guidance that the GML uses to hit targets better, and MissileB.lua is your standard point-at-target homing.


Attachments:
Missile Scripts.rar [1.83 KiB]
Downloaded 341 times
Tue Jul 10, 2012 2:48 am
Profile
User avatar

Joined: Tue Apr 01, 2008 4:49 pm
Posts: 1972
Location: The Netherlands
Reply with quote
Post Re: Request: Homing missile ignoring peeps behind terrain
Thanks, CaveCricket.
They both have the missile aim at enemies, but the missile still doesn't go towards them. It keeps going in a straight line. :oops:
The missile 'looks' at its target and tracks it as it just flies by.
Attachment:
missile2.png
missile2.png [ 2.89 KiB | Viewed 7434 times ]

I guess it must be related to my missile, although it has a pushing emitter. I'll try comparing it with yours again.


Last edited by Gotcha! on Tue Jul 10, 2012 11:58 am, edited 1 time in total.



Tue Jul 10, 2012 11:54 am
Profile
User avatar

Joined: Mon Oct 11, 2010 1:15 pm
Posts: 594
Location: Finlandia
Reply with quote
Post Re: Request: Homing missile ignoring peeps behind terrain
Gotcha! wrote:
They both have the missile aim at enemies, but the missile still doesn't go towards them. It keeps going in a straight line.
The missile 'looks' at its target and tracks it as it just flies by.

Ironically, this is exactly what I was looking for. :lol:


Tue Jul 10, 2012 11:57 am
Profile
User avatar

Joined: Tue Apr 01, 2008 4:49 pm
Posts: 1972
Location: The Netherlands
Reply with quote
Post Re: Request: Homing missile ignoring peeps behind terrain
Err, how could such a function be useful? ^_^'


Tue Jul 10, 2012 11:59 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Request: Homing missile ignoring peeps behind terrain
I tested the scripts with plain Coalition Missile Launcher missiles, it works for them too. Mind if I see your missile code?


Tue Jul 10, 2012 10:40 pm
Profile
User avatar

Joined: Sun Jan 28, 2007 10:32 pm
Posts: 1609
Location: UK
Reply with quote
Post Re: Request: Homing missile ignoring peeps behind terrain
Gotcha! wrote:
Err, how could such a function be useful? ^_^'


Well, if your 'missile' was in fact some kind of gun drone... launch it over a mob/obstacle/whatever and have it scripted to spit the bullet particles at any enemies it detects. That'd be pretty useful, no?


Tue Jul 10, 2012 10:51 pm
Profile YIM
User avatar

Joined: Tue Apr 01, 2008 4:49 pm
Posts: 1972
Location: The Netherlands
Reply with quote
Post Re: Request: Homing missile ignoring peeps behind terrain
@CaveCricket48: Sure! But, err, believe it or not, I was comparing your missile with mine 30 minutes ago, modifying stuff that shouldn't matter according to my logic, and I found the problem. :grin:
Seems OrientToVel = 1 is a bad property to use in conjunction with those scripts. :oops: When that is there they just stop working.

Now all I need to do is balance the amount of emitted particles to have the right flight speed.

Thanks, man! :grin:

Edit: Oh, and your experimental script is bloody amazing, man! O_O

@Arcalane: Hmm, yes, I guess so. My fantasy is way too limited.


Tue Jul 10, 2012 11:14 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 12 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.087s | 15 Queries | GZIP : Off ]