Joined: Sun Jan 28, 2007 10:32 pm Posts: 1609 Location: UK
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
cyclops0000
Joined: Sat Dec 22, 2012 3:24 am Posts: 12
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
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
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
cyclops0000
Joined: Sat Dec 22, 2012 3:24 am Posts: 12
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
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 if UInputMan:KeyPressed(6) == true then self.RotAngle = SceneMan:ShortestDistance(self.Pos,self.target.Pos,true).AbsRadAngle self.Vel = Vector(100, 0):RadRotate(self.RotAngle) print(self.RotAngle)
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 < 50000 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 end if UInputMan:KeyPressed(7) then print(self.RotAngle) print(self.target) print(self.ignoreteam) end end function Destroy(self) if self:IsPlayerControlled() == true then if UInputMan:KeyPressed(19) == false then self:GibThis() end end end
P.S. How's my tabbing?
Sun Dec 23, 2012 6:28 am
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
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
cyclops0000
Joined: Sat Dec 22, 2012 3:24 am Posts: 12
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.
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)
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