Data Realms Fan Forums
http://45.55.195.193/

Appearing behind target
http://45.55.195.193/viewtopic.php?f=73&t=23876
Page 1 of 1

Author:  Asklar [ Sat May 21, 2011 9:50 pm ]
Post subject:  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?

Author:  CaveCricket48 [ Sat May 21, 2011 9:56 pm ]
Post subject:  Re: Appearing behind target

So, the user doesn't teleport at all?

Author:  Asklar [ Sat May 21, 2011 10:01 pm ]
Post subject:  Re: Appearing behind target

No, it's not moving. Any ideas of why this is happening?

Author:  CaveCricket48 [ Sat May 21, 2011 10:43 pm ]
Post subject:  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.

Author:  Asklar [ Sat May 21, 2011 10:45 pm ]
Post subject:  Re: Appearing behind target



There, the entire script. I don't get errors at all, everything works perfect. Well, everything except Technique 8.

Author:  CaveCricket48 [ Sat May 21, 2011 11:57 pm ]
Post subject:  Re: Appearing behind target

Dump a few print() inside 'Technique == 8'

Printing the 'self.target.Pos' might be helpful too.

Author:  Asklar [ Sun May 22, 2011 12:30 am ]
Post subject:  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.

Author:  Xery [ Sun May 22, 2011 4:47 am ]
Post subject:  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).

Author:  Asklar [ Sun May 22, 2011 5:31 am ]
Post subject:  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?

Author:  Xery [ Sun May 22, 2011 7:07 am ]
Post subject:  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.

Author:  Asklar [ Sun May 22, 2011 7:51 am ]
Post subject:  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.

Author:  Xery [ Sun May 22, 2011 8:23 am ]
Post subject:  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

It's somewhat strange according to your description about the function.

Author:  Asklar [ Sun May 22, 2011 8:10 pm ]
Post subject:  Re: Appearing behind target

I'll try that Xery.

Much thanks, you are a pretty good scripter.

Author:  Xery [ Sun May 22, 2011 8:44 pm ]
Post subject:  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

Author:  CaveCricket48 [ Sun May 22, 2011 9:01 pm ]
Post subject:  Re: Appearing behind target

I use (3) for line-based detection and (1) for area-based detection.

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