Data Realms Fan Forums
http://forums.datarealms.com/

Quick question about choosing homing targets
http://forums.datarealms.com/viewtopic.php?f=73&t=39736
Page 2 of 2

Author:  Arcalane [ Sun Dec 23, 2012 3:54 am ]
Post subject:  Re: Quick question about choosing homing targets

That'd be why it would be flying straight right then -- I had a similar issue with homing missile scripting a while back. You'll need to add a check to ensure it doesn't target actors that are on the same team as it. Should be simple enough to do.

Author:  cyclops0000 [ Sun Dec 23, 2012 4:46 am ]
Post subject:  Re: Quick question about choosing homing targets

I already have that implemented, yet it still targets itself.
Code:
function Create(self)
   self.ignoreteam = self.team
end
function Update(self)
   if self:IsPlayerControlled() == true then
      if  UInputMan:KeyPressed(19) == true then
         self:GibThis()
      end
   end
   if self:IsPlayerControlled() == true then
      if MovableMan:IsActor(self.target) then
         self.RotAngle = SceneMan:ShortestDistance(self.Pos,self.target.Pos,true).AbsRadAngle
            if UInputMan:KeyPressed(6) == true then
               self.Vel = Vector(100, 0):RadRotate(self.RotAngle)
               print(self.RotAngle)
            end
         else      
            self.shortestdistance = 1
            for actor in MovableMan.Actors do
               if actor.Team ~= self.ignoreteam then
                  self.curdist = SceneMan:ShortestDistance(self.Pos,actor.Pos,true).Magnitude
                     if self.curdist < 250 and (self.shortestdistance == -1 or self.shortestdistance ~= -1 and self.curdist < self.shortestdistance) then
                        self.target = actor
                        self.shortestdistance = self.curdist
                     end
               end
            end
      end
   end
   if UInputMan:KeyPressed(7)   then
      print(self.RotAngle)
      print(self.target)
   end
end
function Destroy(self)
   if self:IsPlayerControlled() == true then
      if UInputMan:KeyPressed(19) == false then
         self:GibThis()
      end
   end
end

Author:  Asklar [ Sun Dec 23, 2012 6:14 am ]
Post subject:  Re: Quick question about choosing homing targets

I don't see any check for that.

EDIT:

But it's still wierd, he shouldn't target itself anyway because you already put some checks for the team.

Hmm.... Wierd.

EDITEDIT:

Did you try creating another variable for to store the RotAngle and then assigning it to the velocity vector?

Author:  cyclops0000 [ Sun Dec 23, 2012 6:28 am ]
Post subject:  Re: Quick question about choosing homing targets

I realized what part of the problem was, I did self.ignoreteam = self.team instead of self.ignoreteam = self.Team

but alas, still no dice.

I believe the problem is somewhere around if UInputMan:KeyPressed(6) == true because I have it print out the RotAngle, but it never prints out, so it never gets to that point in the program. My current code is


P.S. How's my tabbing?

Author:  Asklar [ Sun Dec 23, 2012 6:31 am ]
Post subject:  Re: Quick question about choosing homing targets

Yeah, noticed your tabbing is better, makes things easier to read.

Well, are you getting a target after all?

Author:  cyclops0000 [ Sun Dec 23, 2012 8:04 pm ]
Post subject:  Re: Quick question about choosing homing targets

No, it doesn't get a target, but the whole chunk of code where it checks if f is pressed then rotates doesn't run.

EDIT: I took out all the bits of code i thought might hinder the targetting, such as the wait for F key and the check if its controlled by the player, it still doesn't work.

EDITEDIT: I completely re-wrote the homing bit with what i thought was the exact same code, but i guess I fixed something, because it homes! the only problem is that if it attempts home through land, the game crashes.

Author:  Shook [ Mon Dec 24, 2012 8:09 pm ]
Post subject:  Re: Quick question about choosing homing targets

I've noticed that you wrote "self.team" rather than "self.Team" (as in capitalized T), which could likely prevent it from ignoring your own dudes. Also, another thing is this line:
Code:
                     if self.curdist < 250 and (self.shortestdistance == -1 or self.shortestdistance ~= -1 and self.curdist < self.shortestdistance) then

Basically you're checking if curdist is smaller than shortestdistance, the latter of which you've set to be 1 previously, so that probably gets in the way of your Lua magic. (in that it only checks if shortestdistance == -1 or if it's smaller than 1)

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