Data Realms Fan Forums
http://45.55.195.193/

Turret Firing Restriction
http://45.55.195.193/viewtopic.php?f=73&t=20918
Page 1 of 1

Author:  thesoupiest [ Mon Dec 27, 2010 4:22 pm ]
Post subject:  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?

Author:  Sean Mirrsen [ Mon Dec 27, 2010 10:18 pm ]
Post subject:  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.

Author:  thesoupiest [ Mon Dec 27, 2010 10:40 pm ]
Post subject:  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?

Author:  Sean Mirrsen [ Mon Dec 27, 2010 11:19 pm ]
Post subject:  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.

Author:  thesoupiest [ Tue Dec 28, 2010 2:39 am ]
Post subject:  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.

Author:  Grif [ Tue Dec 28, 2010 2:56 am ]
Post subject:  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.

Author:  thesoupiest [ Tue Dec 28, 2010 3:19 am ]
Post subject:  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.

Author:  Grif [ Tue Dec 28, 2010 3:56 am ]
Post subject:  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.

Author:  Sean Mirrsen [ Tue Dec 28, 2010 7:11 am ]
Post subject:  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?

Author:  411570N3 [ Tue Dec 28, 2010 7:24 am ]
Post subject:  Re: Turret Firing Restriction

Yes, but always relative to the horizontal and in an arc centred to the same.

Author:  findude [ Tue Dec 28, 2010 2:59 pm ]
Post subject:  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.

Author:  Abdul Alhazred [ Tue Dec 28, 2010 3:26 pm ]
Post subject:  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

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