View unanswered posts | View active topics It is currently Fri Dec 27, 2024 10:44 pm



Reply to topic  [ 8 posts ] 
 Need help with this: VTOL Base 
Author Message
User avatar

Joined: Fri Dec 28, 2007 4:19 am
Posts: 1119
Reply with quote
Post Need help with this: VTOL Base
Sorry for my newbie lua scripting, as I have no idea what I am doing.
What I'm trying to do:
<Assuming that the VTOL's GlobalAccScalar = 0>
Up accelerates the VTOL up until a certain velocity, etc.
When no movement commands are pressed, the VTOL decelerates by itself.

I'm using a AHuman as the VTOL's base.

Code:
function Create(self)
   --For "dynamic" acceleration and deceleration
   moveTimer = Timer();
   --This will be used for acceleration and deceleration.
    self.acceleration = 5;
   
end

function Update(self)
      
   if self:GetController():IsState(Controller.MOVE_LEFT) and self.Vel.X < 20 then
      self.Vel.X = self.Vel.X + 5*moveTimer.ElapsedSimTimeS;
   elseif self:GetController():IsState(Controller.MOVE_RIGHT) and self.Vel.X  < -20 then
      self.Vel.X = self.Vel.X - 5*moveTimer.ElapsedSimTimeS;
   elseif self:GetController():IsState(Controller.BODY_JUMP ) and self.Vel.Y  < 20 then
      self.Vel.Y = self.Vel.Y + 5*moveTimer.ElapsedSimTimeS;
   elseif self:GetController():IsState(Controller.MOVE_DOWN) and self.Vel.Y  < -20 then
      self.Vel.Y = self.Vel.Y - 5*moveTimer.ElapsedSimTimeS;
   else
      if self:GetController():IsState(Controller.MOVE_IDLE ) then
         -- If X velocity is positive
         if self.Vel.X*(-1) = -self.Vel.X and self.Vel.X != 0 then
            self.Vel.X = self.Vel.X - 5*moveTimer.ElapsedSimTimeS;
         -- If X velocity is negative
         elseif self.Vel.X*(-1) = self.Vel.X and self.Vel.X != 0 then
            self.Vel.X = self.Vel.X + 5*moveTimer.ElapsedSimTimeS;
         end

         -- If Y velocity is positive
         if self.Vel.Y*(-1) = -self.Vel.Y and self.Vel.Y != 0 then
            self.Vel.Y = self.Vel.Y - 5*moveTimer.ElapsedSimTimeS;
         -- If Y velocity is negative
         elseif self.Vel.Y*(-1) = self.Vel.Y and self.Vel.Y != 0 then
            self.Vel.Y = self.Vel.Y + 5*moveTimer.ElapsedSimTimeS;
         end
      end
   end
end


Thu Sep 24, 2009 6:05 am
Profile
User avatar

Joined: Sun May 31, 2009 1:04 am
Posts: 308
Reply with quote
Post Re: Need help with this: VTOL Base
You got the idea down good. However, there are a few things wrong. For one, to do 'not equal' in Lua, you use ~= instead of !=. Also, if your going to use a timer to control the acceleration, you might want to rework your code.

At no time does your timer reset. The timer starts when the aircraft is created. So lets say you wait 30 seconds before touching your controls. Then when you press the MOVE_LEFT key (at ElaspedSimTimeS = 30), the number added to your X velocity will be 30*5 = 150. In CC, that means your probably going to smash into the nearest wall at warp speed.


Thu Sep 24, 2009 7:11 am
Profile
User avatar

Joined: Fri Dec 28, 2007 4:19 am
Posts: 1119
Reply with quote
Post Re: Need help with this: VTOL Base
Kyred wrote:
You got the idea down good. However, there are a few things wrong. For one, to do 'not equal' in Lua, you use ~= instead of !=. Also, if your going to use a timer to control the acceleration, you might want to rework your code.

At no time does your timer reset. The timer starts when the aircraft is created. So lets say you wait 30 seconds before touching your controls. Then when you press the MOVE_LEFT key (at ElaspedSimTimeS = 30), the number added to your X velocity will be 30*5 = 150. In CC, that means your probably going to smash into the nearest wall at warp speed.


Though the first problem for me is getting the VTOL to move!

EDIT:
aka I don't really care if its warp speed, just need the craft to move somehow, it's the first thing that'll tell me that its going the right direction. However it doesn't budge at all.


Thu Sep 24, 2009 3:08 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Need help with this: VTOL Base
Your code is set up in a pretty bad manner. Assuming everything works, you'd still have to be moving less than 20 right, left, up, and down (respectively) to be able to move freely, and there's absolutely no support for multiple keypresses.


Thu Sep 24, 2009 11:30 pm
Profile
User avatar

Joined: Fri Dec 28, 2007 4:19 am
Posts: 1119
Reply with quote
Post Re: Need help with this: VTOL Base
Is there anyway to make script spawned MOSRotatings draw after the "parent"? It only seems to draw the specified MOSRotating behind the "parent".


Sat Sep 26, 2009 6:48 am
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Need help with this: VTOL Base
MOSRs (and all other particles) are hardcoded to draw behind actors, which are always drawn behind craft.


Sat Sep 26, 2009 4:17 pm
Profile
User avatar

Joined: Fri Dec 28, 2007 4:19 am
Posts: 1119
Reply with quote
Post Re: Need help with this: VTOL Base
As well, I recall attachables not being able to be scripted?


Sat Sep 26, 2009 4:36 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Need help with this: VTOL Base
Attachables with lua on them will not run said lua.

They can still be found with some workarounds, but it's not necessarily going to be worth it.


Sat Sep 26, 2009 4:44 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 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.022s | 14 Queries | GZIP : Off ]