Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
Appearing behind target
I'm trying to make a gun that when it is fired it makes you appear behind your target and facing it, but it's not working.
Code:
elseif self.Technique == 8 then if self.target.HFlipped == false and self.parent.HFlipped == false then self.parent.Pos = self.target.Pos + Vector(18,0) self.parent.HFlipped = true elseif self.target.HFipped == true and self.parent.HFlipped == true then self.parent.Pos = self.target.Pos - Vector(18,0) self.parent.HFlipped = false elseif self.target.HFipped == false and self.parent.HFlipped == true then self.parent.Pos = self.target.Pos - Vector(18,0) self.parent.HFlipped = false elseif self.target.HFipped == true and self.parent.HFlipped == false then self.parent.Pos = self.target.Pos + Vector(18,0) self.parent.HFlipped = true end end
I've already put some prints in other parts of the code to check that every variable is working, it recognizes the parent, the target, that self.Technique == 8, but it won't work.
Help?
Sat May 21, 2011 9:50 pm
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
Re: Appearing behind target
So, the user doesn't teleport at all?
Sat May 21, 2011 9:56 pm
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
Re: Appearing behind target
No, it's not moving. Any ideas of why this is happening?
Sat May 21, 2011 10:01 pm
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
Re: Appearing behind target
Everything looks fine to me. You sure 'self.Technique' is being set to 8?
Posting the entire script might help too.
Sat May 21, 2011 10:43 pm
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
Re: Appearing behind target
Code:
function Create(self) self.Technique = 0 if UInputMan:KeyHeld(75) and UInputMan:KeyHeld(18) then self.Technique = 6 elseif UInputMan:KeyHeld(75) and UInputMan:KeyHeld(6) then self.Technique = 7 elseif UInputMan:KeyHeld(75) and UInputMan:KeyHeld(3) then self.Technique = 8 elseif UInputMan:KeyHeld(6) then self.Technique = 2 elseif UInputMan:KeyHeld(3) then self.Technique = 3 elseif UInputMan:KeyHeld(22) then self.Technique = 4 elseif UInputMan:KeyHeld(75) then self.Technique = 5 elseif UInputMan:KeyHeld(18) then self.Technique = 1 elseif UInputMan:KeyHeld(6) then self.Technique = 2 end local curdist = 35 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:HasObject("CQC Skills") then curdist = dist; self.parent = actor; end end
local curdist = 35 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 not(actor:HasObject("CQC Skills")) then curdist = dist; self.target = actor; end end end
function Update(self) print(self.Technique) if self.Technique == 0 then self.target.Vel.X = self.Vel.X/2 self.target.Vel.Y = self.Vel.Y/2 elseif self.Technique == 1 then self.target.Vel.X = self.Vel.X/3 self.target.Vel.Y = -16.6 elseif self.Technique == 2 then self.target.Vel.X = (self.Vel.X/2) * -1 self.target.Vel.Y = -15 elseif self.Technique == 3 then self.target.Vel.X = self.Vel.X * 4 self.target.Vel.Y = self.Vel.Y * 4 self.target.Health = self.target.Health - 50 elseif self.Technique == 4 then self.target.Health = 0 elseif self.Technique == 5 then self.target.Vel.Y = -16 self.parent.Vel.Y = -16.5 elseif self.Technique == 6 then self.target.Vel.Y = 20 self.target.Vel.X = self.Vel.X/2 elseif self.Technique == 7 then self.target.Vel.Y = 18 self.target.Vel.X = self.Vel.X/2 * -1 elseif self.Technique == 8 then if self.target.HFlipped == false and self.parent.HFlipped == false then self.parent.Pos = self.target.Pos + Vector(18,0) self.parent.HFlipped = true elseif self.target.HFipped == true and self.parent.HFlipped == true then self.parent.Pos = self.target.Pos - Vector(18,0) self.parent.HFlipped = false elseif self.target.HFipped == false and self.parent.HFlipped == true then self.parent.Pos = self.target.Pos - Vector(18,0) self.parent.HFlipped = false elseif self.target.HFipped == true and self.parent.HFlipped == false then self.parent.Pos = self.target.Pos + Vector(18,0) self.parent.HFlipped = true end end end
There, the entire script. I don't get errors at all, everything works perfect. Well, everything except Technique 8.
Sat May 21, 2011 10:45 pm
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
Re: Appearing behind target
Dump a few print() inside 'Technique == 8'
Printing the 'self.target.Pos' might be helpful too.
Sat May 21, 2011 11:57 pm
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
Re: Appearing behind target
I added this:
Code:
elseif self.Technique == 8 then print(self.target.Pos) if self.target.HFlipped == false and self.parent.HFlipped == false then self.parent.Pos = self.target.Pos + Vector(18,0) self.parent.HFlipped = true print(self.target.Pos.."LOL") elseif self.target.HFipped == true and self.parent.HFlipped == true then self.parent.Pos = self.target.Pos - Vector(18,0) self.parent.HFlipped = false
print(self.target.Pos.."LOL2") elseif self.target.HFipped == false and self.parent.HFlipped == true then self.parent.Pos = self.target.Pos - Vector(18,0) self.parent.HFlipped = false
print(self.target.Pos.."LOL34") elseif self.target.HFipped == true and self.parent.HFlipped == false then self.parent.Pos = self.target.Pos + Vector(18,0) self.parent.HFlipped = true
print(self.target.Pos.."LOL69") end end
To the script, but it is only printing the first print, so it is actually considering that it is in Technique == 8, but it is not considering the other if inside that if, because it hasn't printed anything with LOL.
Sun May 22, 2011 12:30 am
Xery
Joined: Sat Feb 26, 2011 10:29 am Posts: 163
Re: Appearing behind target
Is your gun a super-close combat weapon? Cause I found the script only search target in function Create(self), and the detection range is only 35(the same as parent searching).
Sun May 22, 2011 4:47 am
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
Re: Appearing behind target
Uhm, CQC Skills isn't enough clue?
Well, you know to code pretty well too, can you see why it isn't working?
Sun May 22, 2011 5:31 am
Xery
Joined: Sat Feb 26, 2011 10:29 am Posts: 163
Re: Appearing behind target
I didn't notice the meaning of "CQC" before you remind me of it(shame I put these code into my mod and tested several times, quite sure that the code in OP is the problem. Gonna make further checks. ------------------------------------------------------------------- Done. More simple code, and it works. But I don't know why. The code's tested in an actor's script. Not sure if it works on bullets.
elseif self.Technique == 8 then if target.HFlipped then self.parent.Pos = target.Pos + Vector(21,0); self.parent.HFlipped = true; else self.parent.Pos = target.Pos - Vector(21,0); self.parent.HFlipped = false; end break; end
Sun May 22, 2011 7:07 am
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
Re: Appearing behind target
You condemned Xery, I found out why you made it work!
It's because of this:
Code:
if not self.target.HFlipped and not self.parent.HFlipped then self.parent.Pos = self.target.Pos + Vector(18,0) self.parent.HFlipped = true elseif self.target.HFlipped and self.parent.HFlipped then self.parent.Pos = self.target.Pos - Vector(18,0) self.parent.HFlipped = false elseif not self.target.HFlipped and self.parent.HFlipped then self.parent.Pos = self.target.Pos - Vector(18,0) self.parent.HFlipped = false elseif self.target.HFlipped and not self.parent.HFlipped then self.parent.Pos = self.target.Pos + Vector(18,0) self.parent.HFlipped = true
In the if statement, you must place self.HFlipped or not self.HFlipped rather than self.HFlipped == true or self.HFlipped == false!
Damn, thanks Xery, that was a lot of help. Serious.
Sun May 22, 2011 7:51 am
Xery
Joined: Sat Feb 26, 2011 10:29 am Posts: 163
Re: Appearing behind target
But.....why? I'd replaced all of these in my mod because I feel it looking better, however, they should be the same in theory.
Also, your code can be simplified as
if self.parent.HFlipped then self.parent.Pos = self.target.Pos - Vector(18,0) self.parent.HFlipped = true else self.parent.Pos = self.target.Pos - Vector(18,0) self.parent.HFlipped = false end
It's somewhat strange according to your description about the function.
Sun May 22, 2011 8:23 am
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
Re: Appearing behind target
I'll try that Xery.
Much thanks, you are a pretty good scripter.
Sun May 22, 2011 8:10 pm
Xery
Joined: Sat Feb 26, 2011 10:29 am Posts: 163
Re: Appearing behind target
Asklar wrote:
I'll try that Xery.
Much thanks, you are a pretty good scripter.
My pleasure. Btw, can anyone tell me that which choice below is better for detection? 1.ShortestDistance 2.dist < math.sqrt(avgx ^ 2 + avgy ^ 2) 3.CastMORay
Sun May 22, 2011 8:44 pm
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
Re: Appearing behind target
I use (3) for line-based detection and (1) for area-based detection.
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