View unanswered posts | View active topics It is currently Fri Dec 27, 2024 8:09 am



Reply to topic  [ 12 posts ] 
 Turret Firing Restriction 
Author Message
User avatar

Joined: Thu Dec 16, 2010 11:06 pm
Posts: 276
Reply with quote
Post Turret Firing Restriction
I'm trying to force my turret to not rotate past certain points, and I'm using this lua to do so.
Code:
function Update(self)
   self:GetController():SetState(Controller.MOVE_RIGHT, false)
   self:GetController():SetState(Controller.MOVE_LEFT, false)
   self.Pos = self.startPos

   if self.Gun and self.Gun:IsAttached() then
      if self.HFlipped then
         if self.Gun.RotAngle > 0.7 then
            self.Gun.RotAngle = 0.7
         end
      elseif self.Gun.RotAngle < 0.45 then
         self.Gun.RotAngle = 0.45
      end
   end
end

This serves to restrict the turret to a certain arc when facing right, but when it faces left, it can aim farther downward than I specify.
There is also an issue where using the mouse to aim outside where the turret actually can face will still fire the projectile in the mouse's direction. This is an issue, as my turret fires high-explosive rounds and so kills itself in doing so.
Would anyone help me solve these problems?


Mon Dec 27, 2010 4:22 pm
Profile
User avatar

Joined: Fri Jun 19, 2009 5:57 pm
Posts: 84
Reply with quote
Post Re: Turret Firing Restriction
If your turret is an actor, :GetAimAngle(true/false) is what you're looking for. The true/false bit specifies whether or not to compensate for facing. I'm not sure about whether SetAimAngle exists, but you could try that too. The angle returned by GetAimAngle is in radians.


Mon Dec 27, 2010 10:18 pm
Profile
User avatar

Joined: Thu Dec 16, 2010 11:06 pm
Posts: 276
Reply with quote
Post Re: Turret Firing Restriction
I'm not quite as familiar with .lua as I'd like to be, and this is going to sound like quite an imposition, but would you be able to write out that little snippet of code?


Mon Dec 27, 2010 10:40 pm
Profile
User avatar

Joined: Fri Jun 19, 2009 5:57 pm
Posts: 84
Reply with quote
Post Re: Turret Firing Restriction
Basically, your code with the angle check changed:
Code:
function Update(self)
   self:GetController():SetState(Controller.MOVE_RIGHT, false)
   self:GetController():SetState(Controller.MOVE_LEFT, false)
   self.Pos = self.startPos

   if self.Gun and self.Gun:IsAttached() then
      if ToActor(self):GetAimAngle(false) > 0.7 then
            ToActor(self):SetAimAngle(0.7);
      elseif ToActor(self):GetAimAngle(false) < 0.45 then
            ToActor(self):SetAimAngle(0.45);
      end
   end
end
The ToActor(self) may not be needed, I'm just copying what I have in my SWAT Kats mod. There's no need to check HFlipped, because GetAimAngle(false) already checks the whole angle spectrum.
The example above MIGHT not work, but I can't see anything wrong with it right now.


Mon Dec 27, 2010 11:19 pm
Profile
User avatar

Joined: Thu Dec 16, 2010 11:06 pm
Posts: 276
Reply with quote
Post Re: Turret Firing Restriction
Thank you so much. This works perfectly in fixing the issues of one side being more restricted than the other. However, and I really, really, really don't want to sound critical or anything because everything you're doing is out of your own kindness and generosity, the script was initially meant to restrict the turret from firing downward, or anything past a 45 degree angle, really, and that snippet of script does not quite do that.
Please, if you have the time, help me out if you can.


Tue Dec 28, 2010 2:39 am
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Turret Firing Restriction
Then fix the boundaries.

And do it yourself.

AimAngle is measured in radians. There are 2 * pi radians in one full circle.

0 radians is the 'top' of the circle, or an actor looking straight up.

+/- 1 radian (math.pi) is the bottom of the circle.

Positive decimal radians are the right side of the circle (pretty sure)
Negative decimal radians are the left. See how that works? (again, not 100% sure, but I believe that's correct)

HFlipped is true when you're pointing to the left.

Figure it out.


Tue Dec 28, 2010 2:56 am
Profile
User avatar

Joined: Thu Dec 16, 2010 11:06 pm
Posts: 276
Reply with quote
Post Re: Turret Firing Restriction
Aaalrighty then!
(I couldn't help but read all of that in Nicholas Cage's voice.)
EDIT: I now have a new problem altogether.
I've tried manipulating the variables every which way, and attaching the lua script to every part of the turret. I've even set some variables to absurd settings just to see if it did anything. It does not.
The lua script is not affecting its aiming at all.


Tue Dec 28, 2010 3:19 am
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Turret Firing Restriction
When manually controlled you...probably won't be able to mess with the angles.

So, either A: live with it, and accept that it will only work in AI mode

or B: (much, much more complicated) make a fake turret that listens in to controller presses. It's, obviously, much more complicated, but gives you much more control.


Tue Dec 28, 2010 3:56 am
Profile
User avatar

Joined: Fri Jun 19, 2009 5:57 pm
Posts: 84
Reply with quote
Post Re: Turret Firing Restriction
Actually, you'll need "a turret within a turret". One turret is actually controllable but invisible, while the other is the one that actually aims and fires. It's not THAT much more complicated, but it's certainly beyond basic-level Lua.

Also, maybe my memory deceives me, but don't ACrabs have a firing arc limiting mechanism built in?


Tue Dec 28, 2010 7:11 am
Profile
User avatar

Joined: Wed Jan 07, 2009 10:26 am
Posts: 4074
Location: That quaint little British colony down south
Reply with quote
Post Re: Turret Firing Restriction
Yes, but always relative to the horizontal and in an arc centred to the same.


Tue Dec 28, 2010 7:24 am
Profile WWW
User avatar

Joined: Tue Dec 12, 2006 3:10 pm
Posts: 495
Location: Uncertain quantum state
Reply with quote
Post Re: Turret Firing Restriction
Scripts only run on objects directly owned by the MovableManager.
Attachables are not one of them. Only a script defined for the base of the ACrab will run.

That script doesn't care whether it's the AI or an player trying to aim beyond the boundary.


Tue Dec 28, 2010 2:59 pm
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: Turret Firing Restriction
SetAimAngle is overridden by SharpAim so it can not be used to solve this particular problem. I believe your (my) original code is correct but maybe you have to play with the angle limits some more. I'm pretty sure the self.Gun.RotAngle is always [-pi/2 .. pi/2] where pi/2 is straight up, even if the turret is flipped.

Edit: I was wrong, -pi/2 is straight up when the self.Gun.HFlipped is true and Pi/2 is straight up when the self.Gun.HFlipped is false. I think.

Edit2: Made a diagram just to make sure I'm not lying.
Image


Tue Dec 28, 2010 3:26 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 12 posts ] 

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.048s | 14 Queries | GZIP : Off ]