Joined: Mon Oct 25, 2010 5:51 am Posts: 1198 Location: Sydney
Script: Restricting Aim Angle to for a turret.
Hello, .lua scripters of DRLFF.
Once again, I envy your ability to make weird ♥♥♥♥ happen in Cortex Command, and I seek guidance from your brilliant, logical minds.
Using some of Witty's scripts to attach ACrabs to a dropship, I have a hulking troop transport with a couple of MG mounts. What I would like to do is restrict their aim range to something like what's in the diagram below:
Script so far (all of this is Witty's)
Code:
function Create(self) --thanks so much to whitty for his awesome lua, which im hopeless at --working variables self.Turret = {}; self.Turret.Team = self.Team; --self.DetectTimer[1] = Timer(); --self.Turret[1].IsControllable = false; --create the turrets. self.Turret[1] = CreateACrab("Saucer Defence Turret A"); MovableMan:AddParticle(self.Turret[1]); self.Turret[1].Offset = Vector(60,-14); self.Turret[1].IsControllable = true; self.Turret[2] = CreateACrab("Saucer Defence Turret A"); MovableMan:AddParticle(self.Turret[2]); self.Turret[2].Offset = Vector(-60,-14); self.Turret[2].IsControllable = true; end
function Destroy(self) for i = 1, #self.Turret do if MovableMan:IsParticle(self.Turret[i]) == true then if self.Health < 1 then self.Turret[i]:GibThis() else self.Turret[i].ToDelete = true end end end end
function Update(self)
--update turret spatial properties for i = 1, #self.Turret do if MovableMan:IsParticle(self.Turret[i]) == true then --basic turret position upkeep (so it doesn't fall at 999999m/s) self.Turret[i].Vel.X = 0; self.Turret[i].Vel.Y = 0; --update turret position self.Turret[i].RotAngle = self.RotAngle; self.Turret[i].Pos = self.Pos + self:RotateOffset(self.Turret[i].Offset) end end end
Any help would be appreciated!
Fri Sep 02, 2011 1:39 pm
Mehman
Joined: Tue Nov 17, 2009 7:38 pm Posts: 909 Location: France
Re: Script: Restricting Aim Angle to for a turret.
I'd like to help you but for that I would need the whole .rte to be able to make tests.
Re: Script: Restricting Aim Angle to for a turret.
Start off by defining two turrets, one for left and one for right. Then attach these scripts to them.
Left:
Code:
function Create(self) -- 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) if self.Gun:IsAttached() then -- Restrict aiming: from 0.3 rad below horizon and above if self.Gun.RotAngle > 0.3 then self.Gun.RotAngle = 0.3 end end end
Right:
Code:
function Create(self) -- 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) if self.Gun:IsAttached() then -- Restrict aiming: from 0.3 rad below horizon and above if self.Gun.RotAngle < -0.3 then self.Gun.RotAngle = -0.3 end end end
Credits to Abdul Alhazred for the original.
Sadly, these restrictions do only apply to an equal rotation above and below the horizon. I'll come back if I find a way to do it otherwise.
Fri Sep 02, 2011 2:41 pm
Kettenkrad
Joined: Mon Oct 25, 2010 5:51 am Posts: 1198 Location: Sydney
Re: Script: Restricting Aim Angle to for a turret.
Thanks for the help guys, Roast, that script says that the 'gun' is a nil value or something, I attached the separate ones to the two turrets. Mehman, I'll upload the .rte in the morning, well, later on today. Its quite late here. Thanks again for the help, both of you.
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