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.