View unanswered posts | View active topics It is currently Wed Jan 08, 2025 5:07 am



Reply to topic  [ 10 posts ] 
 Preventing an ACrab from turning 
Author Message
User avatar

Joined: Mon Jun 15, 2009 4:02 pm
Posts: 905
Reply with quote
Post Preventing an ACrab from turning
Well, as the title would suggest, I'm looking for a way to stop an ACrab from being able to turn around.

So far I've tried using CaveCricket's 'prevent people leaping out of windows' script with the fluff ripped out, and I've had a look at the braincase, which won't work, as I can't put a turret on it.
Is this even possible, short of using a dropship?

If it matters at all, I'm making a stationary coastal gun style emplacement that I don't want to turn around.


Mon Mar 29, 2010 5:29 pm
Profile WWW
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Preventing an ACrab from turning
function Create(self)
self.flipped == self.HFlipped;
end

function Update(self)
if self.HFlipped ~= self.flipped then
self.HFlipped = self.flipped;
end
end


Mon Mar 29, 2010 5:40 pm
Profile
User avatar

Joined: Mon Jun 15, 2009 4:02 pm
Posts: 905
Reply with quote
Post Re: Preventing an ACrab from turning
Partially working, but it only works if the player/AI isn't actively trying to turn around. Anything you can do about that?


Mon Mar 29, 2010 6:04 pm
Profile WWW
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Preventing an ACrab from turning
Hmm.

You could check if the actor is getting a move command opposite of the facing direction, and try to cancel it, but I'm not sure if that'd work any better when a real player's using it.


Mon Mar 29, 2010 6:16 pm
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: Preventing an ACrab from turning
The barrel is independent of the actor. Try modifying this script.


Mon Mar 29, 2010 7:19 pm
Profile
User avatar

Joined: Mon Jun 15, 2009 4:02 pm
Posts: 905
Reply with quote
Post Re: Preventing an ACrab from turning
The unit in question doesn't need to move, if that helps at all.

Abdul, which parts do I need to be looking at? Would I be right in thinking that I want to change the RotAngle bits into HFlips?

Ok, I just tried that, and I have some pretty odd results. Time for a spot of debugging, I think.
Code:
function Create(self)
   self.flipped = self.HFlipped;
   -- Find the gun
   for i = 1, MovableMan:GetMOIDCount()-1 do
      if MovableMan:GetRootMOID(i) == self.ID then   -- an obj without a parent has ID == RootID
         self.Gun = MovableMan:GetMOFromID(i)
         if self.Gun.ClassName == "HDFirearm" then
            self.Gun = ToAttachable(self.Gun)
            break
         end
      end
   end
end

function Update(self)
   self:GetController():SetState(Controller.MOVE_RIGHT,false);
   self:GetController():SetState(Controller.MOVE_LEFT,false);
      if self.HFlipped ~= self.flipped then
         self.HFlipped = self.flipped;
   if self.Gun:IsAttached() then
      -- Restrict aiming: from 0.3 rad below horizon and above / lies
      if self.HFlipped then
         if self.Gun.HFlipped ~= self.flipped then
            self.Gun.HFlipped = self.flipped
         end
   end
end
end
end

This is what I have. The problems are as follows:

Turrets that face right act as without your script; that is, they can still turn around if the player tries to, but do correct themselves otherwise.
Turrets that face left that try to turn right fail horribly. Nothing flips, but the gun is on the right (handed) side of the base, the sharpaim points left, but the gun fires right.

Hopefully I described that decently.


Mon Mar 29, 2010 7:41 pm
Profile WWW
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: Preventing an ACrab from turning
Sounds messy, have you tried rotating the barrel by pi instead of flipping? Also, in my experience sharp aiming will always override lua but you could try setting sharp aim to false when facing the wrong direction using SetState. The AI's aim will most likely be screwed up, shooting in the opposite direction, but perhaps you can solve that by manually setting the ViewPoint every frame.


Mon Mar 29, 2010 7:55 pm
Profile
User avatar

Joined: Mon Jun 15, 2009 4:02 pm
Posts: 905
Reply with quote
Post Re: Preventing an ACrab from turning
I've been looking at the Wiki for about half an hour, and I have no idea how to do any of that.

Here is a picture for clarification purposes:

Image

Odd, no?


Mon Mar 29, 2010 8:32 pm
Profile WWW
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: Preventing an ACrab from turning
Try this:
Code:
function Create(self)
   self.flipped = self.HFlipped
   self.Ctrl = self:GetController()

   -- Find the gun
   local thisID = self.ID
   for i = 1, MovableMan:GetMOIDCount()-1 do
      if MovableMan:GetRootMOID(i) == thisID then   -- an obj without a parent has ID == RootID
         self.Gun = MovableMan:GetMOFromID(i)
         if self.Gun.ClassName == "HDFirearm" then
            self.Gun = ToAttachable(self.Gun)
            break
         end
      end
   end
end

function Update(self)
   if self.flipped ~= self.HFlipped then
      self.HFlipped = not self.HFlipped
      if self.Gun and self.Gun:IsAttached() then
         self.ViewPoint = self.Pos
         self.Gun.HFlipped = self.flipped
         self.Ctrl:SetState(Controller.AIM_SHARP, false)
         self.Ctrl:SetState(Controller.WEAPON_FIRE, false)
         
         if self.flipped ~= self.Gun.HFlipped then
            self.ViewPoint = self.Pos
         else
            self.Gun.RotAngle = 0
         end
      end
   end
end

This is not tested so I cannot guarantee you it will work.


Tue Mar 30, 2010 8:02 am
Profile
User avatar

Joined: Mon Jun 15, 2009 4:02 pm
Posts: 905
Reply with quote
Post Re: Preventing an ACrab from turning
Ahh thanks, looks better. Sadly I'm not in a position to test it at the moment, but I'll report back as soon as I get home.

Edit:
I've tested it, and it is nearly perfect, the main issue now being that the turret still does move to the other side of the base, though it can no longer shoot or sharpaim when aiming that way.

Otherwise, the only problem is that the wounds still flip on both the base and turret.
Would I be right in thinking that it's impossible to fix them?

Hmm. Is it possible to turn off aiming all together? Could you try stopping all aiming when HFlip = 1?


Tue Mar 30, 2010 11:17 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 10 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.041s | 15 Queries | GZIP : Off ]