Data Realms Fan Forums http://45.55.195.193/ |
|
Request: Homing missile ignoring peeps behind terrain http://45.55.195.193/viewtopic.php?f=73&t=31423 |
Page 1 of 1 |
Author: | Gotcha! [ Mon Jul 09, 2012 10:03 pm ] |
Post subject: | 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: |
Author: | Roast Veg [ Mon Jul 09, 2012 10:33 pm ] |
Post subject: | 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 |
Author: | Gotcha! [ Mon Jul 09, 2012 11:34 pm ] |
Post subject: | 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. |
Author: | Roast Veg [ Mon Jul 09, 2012 11:53 pm ] |
Post subject: | Re: Request: Homing missile ignoring peeps behind terrain |
MY BAD. |
Author: | Gotcha! [ Tue Jul 10, 2012 12:50 am ] |
Post subject: | 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. 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. |
Author: | CaveCricket48 [ Tue Jul 10, 2012 2:48 am ] | ||
Post subject: | 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.
|
Author: | Gotcha! [ Tue Jul 10, 2012 11:54 am ] |
Post subject: | 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. The missile 'looks' at its target and tracks it as it just flies by. I guess it must be related to my missile, although it has a pushing emitter. I'll try comparing it with yours again. |
Author: | 4zK [ Tue Jul 10, 2012 11:57 am ] |
Post subject: | 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. |
Author: | Gotcha! [ Tue Jul 10, 2012 11:59 am ] |
Post subject: | Re: Request: Homing missile ignoring peeps behind terrain |
Err, how could such a function be useful? ^_^' |
Author: | CaveCricket48 [ Tue Jul 10, 2012 10:40 pm ] |
Post subject: | 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? |
Author: | Arcalane [ Tue Jul 10, 2012 10:51 pm ] |
Post subject: | 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? |
Author: | Gotcha! [ Tue Jul 10, 2012 11:14 pm ] |
Post subject: | 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. Seems OrientToVel = 1 is a bad property to use in conjunction with those scripts. 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! Edit: Oh, and your experimental script is bloody amazing, man! O_O @Arcalane: Hmm, yes, I guess so. My fantasy is way too limited. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |