Data Realms Fan Forums http://45.55.195.193/ |
|
Need help with this: VTOL Base http://45.55.195.193/viewtopic.php?f=73&t=16641 |
Page 1 of 1 |
Author: | DSMK2 [ Thu Sep 24, 2009 6:05 am ] |
Post subject: | 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 |
Author: | Kyred [ Thu Sep 24, 2009 7:11 am ] |
Post subject: | 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. |
Author: | DSMK2 [ Thu Sep 24, 2009 3:08 pm ] |
Post subject: | 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. |
Author: | Grif [ Thu Sep 24, 2009 11:30 pm ] |
Post subject: | 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. |
Author: | DSMK2 [ Sat Sep 26, 2009 6:48 am ] |
Post subject: | 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". |
Author: | Grif [ Sat Sep 26, 2009 4:17 pm ] |
Post subject: | Re: Need help with this: VTOL Base |
MOSRs (and all other particles) are hardcoded to draw behind actors, which are always drawn behind craft. |
Author: | DSMK2 [ Sat Sep 26, 2009 4:36 pm ] |
Post subject: | Re: Need help with this: VTOL Base |
As well, I recall attachables not being able to be scripted? |
Author: | Grif [ Sat Sep 26, 2009 4:44 pm ] |
Post subject: | 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. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |