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