View unanswered posts | View active topics It is currently Mon Jan 13, 2025 6:04 am



Reply to topic  [ 19 posts ]  Go to page Previous  1, 2
 Lua tricks Topic 
Author Message
User avatar

Joined: Tue Dec 12, 2006 3:10 pm
Posts: 495
Location: Uncertain quantum state
Reply with quote
Post Re: Lua tricks Topic
Code:
actor.Health = -1;
actor.ToSettle = true;


Ohai how nice of you to stick around.


Mon Oct 19, 2009 5:31 pm
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: Lua tricks Topic
If you manage to rotate a dropship 360 degrees without braking it and keep it flying right side up, it will still auto scuttle. Probably because self.RotAngle goes above 2*pi. This little snippet prevents it:
Code:
if self.RotAngle > 6.283185 then
    self.RotAngle = self.RotAngle - 6.283185
elseif self.RotAngle < -1.570796 then
    self.RotAngle = self.RotAngle + 6.283185
end


Tue Nov 03, 2009 3:42 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Lua tricks Topic
I used a similar script for the plane, but simplified:

if self.RotAngle > math.pi * 2 then
self.RotAngle = 0;
elseif self.RotAngle < math.pi * -2 then
self.RotAngle = 0;
end


Tue Nov 03, 2009 3:51 pm
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: Lua tricks Topic
This script limits the aiming angle of the actor to [-0.3 .. AimRange] by setting the angle of the weapon attachable every update:
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.HFlipped then
         if self.Gun.RotAngle > 0.3 then
            self.Gun.RotAngle = 0.3
         end
      elseif self.Gun.RotAngle < -0.3 then
         self.Gun.RotAngle = -0.3
      end
   end
end


Thu Mar 25, 2010 6:31 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 19 posts ]  Go to page Previous  1, 2

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