View unanswered posts | View active topics It is currently Thu Mar 28, 2024 3:34 pm



Reply to topic  [ 22 posts ]  Go to page Previous  1, 2
 Quick question about choosing homing targets 
Author Message
User avatar

Joined: Sun Jan 28, 2007 10:32 pm
Posts: 1609
Location: UK
Reply with quote
Post 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.


Sun Dec 23, 2012 3:54 am
Profile YIM

Joined: Sat Dec 22, 2012 3:24 am
Posts: 12
Reply with quote
Post 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


Sun Dec 23, 2012 4:46 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post 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?


Sun Dec 23, 2012 6:14 am
Profile

Joined: Sat Dec 22, 2012 3:24 am
Posts: 12
Reply with quote
Post 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?


Sun Dec 23, 2012 6:28 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post 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?


Sun Dec 23, 2012 6:31 am
Profile

Joined: Sat Dec 22, 2012 3:24 am
Posts: 12
Reply with quote
Post 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.


Sun Dec 23, 2012 8:04 pm
Profile
User avatar

Joined: Fri Feb 16, 2007 8:43 pm
Posts: 1695
Location: AH SHIT FUCK AUGH
Reply with quote
Post 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)


Mon Dec 24, 2012 8:09 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 22 posts ]  Go to page Previous  1, 2

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.574s | 15 Queries | GZIP : Off ]