Advertisement
tyridge77

MechLocal

Oct 6th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.64 KB | None | 0 0
  1. wait(2);
  2. script.Parent = nil;
  3. local player = game:GetService("Players").LocalPlayer;
  4. local rst = game:GetService("RunService").RenderStepped;
  5. local char = Workspace:WaitForChild(player.Name);
  6. char.Humanoid.WalkSpeed = 0;
  7.  
  8. local function GetGunSounds(p)
  9.     return p.Start,p.Shoot,p.End;
  10. end
  11.  
  12.  
  13. local ids = {};
  14. --local function ScanForIds(p)
  15. --  for _,v in pairs(p:GetChildren()) do
  16. --      if v:isA("Sound") then
  17. --          ids[#ids+1]=v.SoundId;
  18. --      else
  19. --          ScanForIds(v);
  20. --      end
  21. --  end
  22. --end
  23. game.ReplicatedStorage.MakeMech:InvokeServer();
  24. local Mech = Workspace:WaitForChild("Mech");
  25. Mech.Name = player.Name.."Mech";
  26. Mech.Parent = char;
  27.  
  28. --ScanForIds(Mech);
  29. --game:GetService("ContentProvider"):PreloadAsync(ids);
  30.  
  31. local LeftLeg = Mech["Left Leg"];
  32. local RightLeg = Mech["Right Leg"];
  33.  
  34.  
  35. local Head = Mech.Head;
  36. local Torso = Mech.Torso;
  37. local EtcTorso = Torso.EtcTorso;
  38.  
  39. local LeftShoulder = Head.LeftShoulder;
  40. local RightShoulder = Head.RightShoulder;
  41.  
  42. local LeftRockets = LeftShoulder.Center.RocketWeld;
  43. local RightRockets = RightShoulder.Center.RocketWeld;
  44.  
  45.  
  46.  
  47. local LeftThruster = LeftShoulder.LeftThruster;
  48. local RightThruster = RightShoulder.RightThruster;
  49.  
  50. local LeftGun = LeftShoulder.LeftGun.Center.GunWeld;
  51.  
  52. local RightGun = RightShoulder.RightGun.Center.GunWeld;
  53.  
  54. local LeftFlashes = {};
  55. local RightFlashes = {};
  56. local LeftRocketHoles = {};
  57. local RightRocketHoles = {};
  58. for _,v in pairs(LeftShoulder.LeftGun:GetChildren()) do
  59.     if v.Name == "Hole" then
  60.         LeftFlashes[#LeftFlashes+1]=v.Flash;
  61.     end
  62. end
  63. for _,v in pairs(RightShoulder.RightGun:GetChildren()) do
  64.     if v.Name == "Hole" then
  65.         RightFlashes[#RightFlashes+1]=v.Flash;
  66.     end
  67. end
  68. for _,v in pairs(RightShoulder:GetChildren()) do
  69.     if v.Name == "RocketHole" then
  70.         RightRocketHoles[#RightRocketHoles+1]=v;
  71.     end
  72. end
  73. for _,v in pairs(LeftShoulder:GetChildren()) do
  74.     if v.Name == "RocketHole" then
  75.         LeftRocketHoles[#LeftRocketHoles+1]=v;
  76.     end
  77. end
  78.  
  79. local LeftGunStart,LeftGunShoot,LeftGunEnd = GetGunSounds(LeftShoulder.LeftGun.Center);
  80. local RightGunStart,RightGunShoot,RightGunEnd = GetGunSounds(RightShoulder.RightGun.Center);
  81.  
  82.  
  83. local LeftGunC0 = LeftGun.C0;
  84.  
  85. local TorsoCenter = Torso.Center;
  86.  
  87. local Thruster = Instance.new("Sound",TorsoCenter);
  88. Thruster.Name = "Thruster";
  89. Thruster.SoundId = "http://roblox.com/asset/?ID=97179333";
  90. Thruster.Volume = 1;
  91.  
  92. local RocketShoot = Instance.new("Sound",TorsoCenter);
  93. RocketShoot.Name = "Fire";
  94. RocketShoot.SoundId = "http://roblox.com/asset/?ID=137991337";
  95. RocketShoot.Volume = .25;
  96.  
  97. local RocketToggle = Instance.new("Sound",TorsoCenter);
  98. RocketToggle.Name = "Toggle";
  99. RocketToggle.SoundId = "http://roblox.com/asset/?ID=293698293";
  100. RocketToggle.Volume = .25;
  101.  
  102. local Kick = Instance.new("Sound",TorsoCenter);
  103. Kick.Name = "Kick";
  104. Kick.Volume = 1;
  105. Kick.Pitch = .8;
  106. Kick.SoundId = "http://roblox.com/asset?id=169380525";
  107.  
  108.  
  109. local HeadCenter = Head.Center;
  110.  
  111. local MoveArms = TorsoCenter.MoveArms;
  112. local Step = TorsoCenter.Step;
  113. local StopMovingArms = TorsoCenter.StopMovingArms;
  114.  
  115. local function playsound(s,step,debris)
  116.     local newsound = s:clone();
  117.     newsound.Parent = TorsoCenter;
  118.     newsound.Pitch = step or 1;
  119.     newsound:Play();
  120.     if debris then
  121.         game.Debris:AddItem(newsound,10);
  122.     end
  123. end
  124. local LeftHip = TorsoCenter.LeftHip;
  125. local RightHip = TorsoCenter.RightHip;
  126. local Neck = TorsoCenter.Neck;
  127.  
  128. local RightShoulder = HeadCenter.RightShoulder;
  129. local LeftShoulder = HeadCenter.LeftShoulder;
  130.  
  131. local LeftHipC0 = LeftHip.C0;
  132. local LeftHipFlyC0 = LeftHipC0*CFrame.new(4,0,0);
  133. local RightHipC0 = RightHip.C0;
  134. local RightHipFlyC0 = RightHipC0*CFrame.new(4,0,0);
  135.  
  136. local Cam = Workspace.CurrentCamera;
  137. Cam.CameraSubject = HeadCenter;
  138.  
  139. local Input = game:GetService("UserInputService");
  140.  
  141. local speed = 0;
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148. local GRAVITY_ACCELERATION = 196.2
  149. local MISSILE_MESH_ID = 'http://www.roblox.com/asset/?id=2251534'
  150. local MISSILE_MESH_SCALE = Vector3.new(0.35, 0.35, 0.25)
  151. local ROCKET_PART_SIZE = Vector3.new(1.2, 1.2, 3.27)
  152.  
  153. local Rocket = Instance.new("Part");
  154. Rocket.Name = 'Rocket'
  155. Rocket.FormFactor = Enum.FormFactor.Custom --NOTE: This must be done before changing Size
  156. Rocket.Size = ROCKET_PART_SIZE
  157. Rocket.CanCollide = false
  158. Rocket.Anchored = true;
  159.  
  160. -- Add the mesh
  161. local mesh = Instance.new('SpecialMesh', Rocket)
  162. mesh.MeshId = MISSILE_MESH_ID
  163. mesh.Scale = MISSILE_MESH_SCALE
  164.  
  165. -- Add fire
  166. local fire = Instance.new('Fire', Rocket)
  167. fire.Heat = 5
  168. fire.Size = 2
  169.    
  170.  
  171.  
  172.  
  173. local function clamp(v,mi,ma)
  174.     if v<mi then return v elseif v>ma then return ma else return v end
  175. end
  176.  
  177. function lerp(a, b, t)
  178.     return a * (1-t) + (b*t)
  179. end
  180.  
  181. local steptime = 0;
  182. local stepreached = false;
  183. local LastSprinting;
  184. local HeadSwayPerc = 0;
  185. local swayorigin = 0;
  186. local lastsway = 0;
  187.  
  188. local Mouse = player:GetMouse();
  189. local Jumping;
  190. local JumpHeadPerc = 0;
  191. local JumpOrigin;
  192.  
  193. local ThrusterCheck = 0;
  194.  
  195. local FaceCamera;
  196. local CamCF = Cam.CoordinateFrame;
  197.  
  198. Mouse.Button2Down:connect(function()
  199.   --  FaceCamera = true;
  200. end)
  201. Mouse.Button2Up:connect(function()
  202.     --FaceCamera = false;
  203.     --CamCF = Cam.CoordinateFrame
  204. end)
  205.  
  206. jumpevent = char.Humanoid.Jumping:connect(function()
  207.     if not Jumping and not Landing then
  208.         Jumping = true;
  209.     end
  210. end)
  211.  
  212. local CFYTime;
  213. local torsoswayperc = 0;
  214. local torsoswayorigin = 0;
  215.  
  216. local LastNeckXYZ = Vector3.new();
  217.  
  218. local LeftGunSpeedPerc = 0;
  219. local RightGunSpeedPerc = 0;
  220.  
  221. local RightFlashCount = 0;
  222. local LeftFlashCount = 0;
  223.  
  224. local RightFlashTime = 0;
  225.  
  226. local LeftFlashTime = 0;
  227.  
  228. local LeftFlashThresh = 0;
  229. local RightFlashThresh = 0;
  230.  
  231. local FlyPerc = 0;
  232.  
  233. local LockHip;
  234.  
  235. local function takedamage(hit)
  236.     if not hit or not hit.Parent then return end
  237.     print(hit,hit.Parent,hit.Parent:FindFirstChild("Humanoid"));
  238.     if hit.Parent:FindFirstChild("Humanoid") then
  239.         hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health-.1;
  240.     elseif hit.Parent.Parent and hit.Parent.Parent:FindFirstChild("Humanoid") then
  241.         hit.Parent.Parent.Humanoid.Health = hit.Parent.Parent.Humanoid.Health-.1;
  242.     end
  243. end
  244.  
  245. local Looking = false;
  246.  
  247.  
  248. local LeftRocketEnabled = false;
  249. local RightRocketEnabled = false;
  250.  
  251. local RightRocketPoint,LeftRocketPoint;
  252.  
  253. local LeftRocketDeb,RightRocketDeb;
  254.  
  255. function color(p)
  256.     for _,v in pairs(p:GetChildren()) do
  257.          if v:isA("BasePart") and v.BrickColor == BrickColor.new("Medium stone grey") then
  258.            v.BrickColor = BrickColor.new("Really black")
  259.              else color(v)
  260.          end
  261.     end
  262. end
  263.  
  264. Mouse.KeyDown:connect(function(k)
  265.     if k == "m" then
  266.         color(Mech);
  267.     end
  268.  
  269.     if k == "f" then
  270.         Looking = not Looking;
  271.     end
  272.     if k == "v" then
  273.         playsound(RocketToggle,false,true);
  274.         LeftRocketEnabled = not LeftRocketEnabled;
  275.         if LeftRocketEnabled then
  276.             LeftRockets.DesiredAngle = 0;
  277.         else
  278.             LeftRockets.DesiredAngle = -1.5;
  279.         end
  280.     end
  281.     if k == "b" then
  282.         playsound(RocketToggle,false,true);
  283.         RightRocketEnabled = not RightRocketEnabled;
  284.         if RightRocketEnabled then
  285.             RightRockets.DesiredAngle = 0;
  286.         else
  287.             RightRockets.DesiredAngle = -1.5;
  288.         end
  289.     end
  290.     if k == "x" and not LeftRocketDeb then
  291.         LeftRocketDeb = true;
  292.         LeftRocketPoint = true;
  293.         wait(5);
  294.         LeftRocketDeb = false;
  295.     end
  296.     if k == "c" and not RightRocketDeb then
  297.         RightRocketDeb = true;
  298.         RightRocketPoint = true;
  299.         wait(5);
  300.         RightRocketDeb = false;
  301.     end
  302. end)
  303.  
  304. local FiringRockets = {};
  305. local lastrocket = {};
  306. while true do
  307.     rst:wait();
  308.     local time = Workspace.DistributedGameTime;
  309.    
  310.     local Sprinting;
  311.     local Walking;
  312.     local ShootRight,ShootLeft;
  313.    
  314.     local ThrusterPlaying;
  315.    
  316.     if FaceCamera then
  317.         CamCF = Cam.CoordinateFrame;
  318.     end
  319.    
  320.    
  321.     local decy = 0;
  322.     local GroundRay = Ray.new(TorsoCenter.Position,Vector3.new(0,-32,0));
  323.     local GroundHit,GroundPos = Workspace:FindPartOnRayWithIgnoreList(GroundRay,{Mech});
  324.    
  325.     local Turning;
  326.    
  327.     FlyPerc=clamp(FlyPerc+0.1,0,1);
  328.    
  329.    
  330.  
  331.     if LeftRocketPoint then
  332.         if not LastLeftRocketPoint then
  333.             for _,v in pairs(LeftRocketHoles) do
  334.                 playsound(RocketShoot,false,true);
  335.                 local rocket = Rocket:clone()
  336.                 local sound = Instance.new("Sound",rocket);
  337.                 sound.SoundId = "http://roblox.com/asset/?ID=144699494";
  338.                 sound.Name = "Explode";
  339.                 sound.Volume = .25;
  340.                 rocket.Parent = Workspace;
  341.                 local ray = Ray.new(Mouse.UnitRay.Origin,Mouse.UnitRay.Direction*999);
  342.                 local hit,pos = Workspace:FindPartOnRayWithIgnoreList(ray,{Mech});
  343.                 local rocketcf = CFrame.new(v.CFrame.p,pos or v.CFrame.lookVector);
  344.                 rocket.CFrame = rocketcf;
  345.                 FiringRockets[#FiringRockets+1]=rocket;
  346.                 lastrocket[rocket]=rocketcf;
  347.             end
  348.             LeftRocketPoint = nil;
  349.         end
  350.     end
  351.     if RightRocketPoint then
  352.         if not LastRightRocketPoint then
  353.             for _,v in pairs(RightRocketHoles) do
  354.                 playsound(RocketShoot,false,true);
  355.                 local rocket = Rocket:clone()
  356.                 local sound = Instance.new("Sound",rocket);
  357.                 sound.SoundId = "http://roblox.com/asset/?ID=144699494";
  358.                 sound.Name = "Explode";
  359.                 rocket.Parent = Workspace;
  360.                 local ray = Ray.new(Mouse.UnitRay.Origin,Mouse.UnitRay.Direction*999);
  361.                 local hit,pos = Workspace:FindPartOnRayWithIgnoreList(ray,{Mech});
  362.                 local rocketcf = CFrame.new(v.CFrame.p,pos or v.CFrame.lookVector);
  363.                 rocket.CFrame = rocketcf;
  364.                 FiringRockets[#FiringRockets+1]=rocket;
  365.                 lastrocket[rocket]=rocketcf;
  366.             end
  367.             RightRocketPoint = nil;
  368.         end
  369.     end
  370.    
  371.     for _,v in pairs(FiringRockets) do
  372.         v.CFrame = v.CFrame*CFrame.new(0,0,-2);
  373.         local ray = Ray.new(v.Position,v.CFrame.lookVector*2);
  374.         lastrocket[v]=v.CFrame;
  375.         local hit,pos = Workspace:FindPartOnRayWithIgnoreList(ray,{Mech});
  376.         if hit and not hit:isDescendantOf(Mech) and hit.Name ~= "Rocket" then
  377.             FiringRockets[_]=nil;
  378.             local exp = Instance.new("Explosion",Workspace);
  379.             exp.Position = pos;
  380.             playsound(v.Explode,false,true);
  381.             v:Destroy();
  382.         end
  383.     end
  384.    
  385.  
  386.     local Flying = false;
  387.    
  388.     if not GroundHit then
  389.         if LastGroundHit then
  390.         FlyPerc = 0;
  391.         LeftThruster.Fire.Enabled = true;
  392.         RightThruster.Fire.Enabled = true;
  393.         end
  394.         Flying = true;
  395.         ThrusterPlaying = true;
  396.         speed = 1;
  397.         LeftHip.C0 = LeftHipC0:lerp(LeftHipFlyC0,FlyPerc);
  398.         RightHip.C0 = RightHipC0:lerp(RightHipFlyC0,FlyPerc);
  399.         LockHip = 1;
  400.     end
  401.     if GroundHit then
  402.         decy = GroundPos.Y-TorsoCenter.CFrame.Y+11;
  403.         if not LastGroundHit then
  404.             local CFr = TorsoCenter.CFrame;
  405.             local CF = CFr*CFrame.new(0,0,-100)
  406.             local New = CFrame.new(CFr.p,Vector3.new(CF.X,CFr.Y,CF.Z))
  407.             TorsoCenter.CFrame = New;
  408.             FlyPerc = 0;
  409.             LeftThruster.Fire.Enabled = false;
  410.             RightThruster.Fire.Enabled = false;
  411.         end
  412.         Flying = false;
  413.         ThrusterPlaying = false;
  414.         LeftHip.C0 = LeftHipFlyC0:lerp(LeftHipC0,FlyPerc);
  415.         RightHip.C0 = RightHipFlyC0:lerp(RightHipC0,FlyPerc);
  416.         LockHip = nil;
  417.     end
  418.    
  419.     if ThrusterPlaying then
  420.         if time-ThrusterCheck >= 3.5 then
  421.             ThrusterCheck=time;
  422.             playsound(Thruster,false,true);
  423.         end
  424.     else
  425.         if LastThrusterPlaying then
  426.             for _,v in pairs(TorsoCenter:GetChildren()) do
  427.                 if v.Name == "Thruster" then
  428.                     v:Stop();
  429.                 end
  430.             end
  431.         end
  432.     end
  433.     if Input:IsKeyDown(Enum.KeyCode.D) then
  434.         Turning = 3;
  435.     end
  436.     if Input:IsKeyDown(Enum.KeyCode.A) then
  437.         Turning = -3;
  438.     end
  439.     if Input:IsKeyDown(Enum.KeyCode.E) then
  440.         ShootRight = true;
  441.     end
  442.     if Input:IsKeyDown(Enum.KeyCode.Q) then
  443.         ShootLeft= true;
  444.     end
  445.     if Input:IsKeyDown(Enum.KeyCode.W) and GroundHit then
  446.         Walking = 1;
  447.     end
  448.     if Input:IsKeyDown(Enum.KeyCode.S) and GroundHit then
  449.         Walking = -1;
  450.     end
  451.     if Input:IsKeyDown(Enum.KeyCode.LeftShift) then
  452.         Sprinting = true;
  453.     end
  454.     if Jumping and not LastJumping then
  455.         JumpHeadPerc = 0;
  456.         JumpOrigin = Neck.C0;
  457.     end
  458.    
  459.     if ShootRight and not LastShootRight then
  460.         RightFlashThresh = 1;
  461.         RightFlashTime = time;
  462.         CoolingRight = false;
  463.         RightGunStart:Play();
  464.         RightGunSpeedPerc = 0;
  465.         RightGunShootTime = time;
  466.     end
  467.     if ShootLeft and not LastShootLeft then
  468.         LeftFlashTime = time;
  469.         LeftFlashThresh = 1;
  470.         CoolingLeft = false;
  471.         LeftGunStart:Play();
  472.         LeftGunSpeedPerc = 0;
  473.         LeftGunShootTime = time;
  474.     end
  475.    
  476.     LeftGunSpeedPerc = clamp(LeftGunSpeedPerc+0.1,0,1);
  477.     RightGunSpeedPerc = clamp(RightGunSpeedPerc+0.1,0,1);
  478.    
  479.     if not ShootLeft and LastShootLeft then
  480.         LeftGunEnd:Play();
  481.         LeftGunShoot:Stop();
  482.         LeftGunStart:Stop();
  483.     end
  484.     if not ShootRight and LastShootRight then
  485.         RightGunEnd:Play();
  486.         RightGunShoot:Stop();
  487.         RightGunStart:Stop();
  488.     end
  489.    
  490.     if LeftGunShootTime and time-LeftGunShootTime >= 1 and ShootLeft then
  491.         LeftGunShoot:Play();
  492.         LeftGunShoot.Looped = true;
  493.         LeftGunShootTime = nil;
  494.     end
  495.     if RightGunShootTime and time-RightGunShootTime >= 1 and ShootRight then
  496.         RightGunShoot:Play();
  497.         RightGunShoot.Looped = true;
  498.         RightGunShootTime = nil;
  499.     end
  500.    
  501.    
  502.     local TorsoCF = TorsoCenter.CFrame*CFrame.Angles(0,math.rad(90),0);
  503.  
  504.     local desangmod;
  505.     local swaygoal;
  506.    
  507.    
  508.     JumpHeadPerc = clamp(JumpHeadPerc+0.1,0,1);
  509.    
  510.    
  511.    
  512.     if Looking then
  513.         if not LastLooking then
  514.             MoveArms:Play();
  515.         end
  516.     else
  517.         if LastLooking then
  518.             StopMovingArms:Play();
  519.             MoveArms:Stop();
  520.         end
  521.     end
  522.    
  523.     if Jumping then
  524.         Neck.C0 = JumpOrigin:lerp(JumpOrigin*CFrame.new(0,-2,0),JumpHeadPerc);
  525.         if JumpHeadPerc >= .99 then
  526.             JumpEnd = Neck.C0;
  527.             JumpHeadPerc = 0;
  528.             Jumping = false;
  529.             JumpStart = true;
  530.             playsound(Step,2,true);
  531.         end
  532.     end
  533.    
  534.     if Jumping == false and JumpStart then
  535.         if JumpEnd then
  536.             Neck.C0 = JumpEnd:lerp(JumpOrigin,JumpHeadPerc);
  537.         end
  538.         TorsoCenter.CFrame = TorsoCenter.CFrame*CFrame.new(0,45,0);
  539.         JumpStart = false;
  540.     end
  541.    
  542.     local sway = 0;
  543.  
  544.     local torsosway;
  545.    
  546.     if Walking then
  547.         local desang = math.sin(time*10);
  548.        
  549.         torsosway =  math.sin(time*10)/(Sprinting and 10 or 40);
  550.        
  551.         if Sprinting ~= LastSprinting then
  552.             swayorigin = lastsway;
  553.             HeadSwayPerc = 0;
  554.         end
  555.            
  556.         if Sprinting then
  557.             desangmod = math.sin(time*20);
  558.         else
  559.             desangmod = math.sin(time*18);
  560.         end
  561.        
  562.        
  563.         if 1-desangmod <= .1 and not stepreached then
  564.             playsound(Step,math.random(100,110)/100,true);
  565.             stepreached = true;
  566.         end
  567.         if desangmod <= .1 then
  568.             stepreached = false;
  569.         end
  570.         if not lastwalking == true then
  571.             speed = 0;
  572.         end
  573.         speed = clamp(speed+0.01,0,Sprinting and 1 or .2);
  574.                
  575.         LeftHip.MaxVelocity = Sprinting and 0.1 or 0.025;
  576.         RightHip.MaxVelocity = Sprinting and 0.1 or 0.025;
  577.         LeftHip.DesiredAngle = LockHip or Walking*desang;
  578.         RightHip.DesiredAngle = LockHip or Walking*-desang;
  579.        
  580.        
  581.         HeadSwayPerc = clamp(HeadSwayPerc+0.01,0,1);
  582.         Neck.MaxVelocity = 0.005; -- Neck sway
  583.         swaygoal = ((Sprinting or (ShootRight or ShootLeft) )and lerp(swayorigin,.01,HeadSwayPerc) or lerp(swayorigin,20,HeadSwayPerc));
  584.         sway = desang/swaygoal;
  585.         Neck.DesiredAngle = sway
  586.        
  587.     else
  588.         Neck.DesiredAngle = 0;
  589.         if lastwalking then
  590.             decayorigin = speed;
  591.             torsoswayorigin = torsosway or 0;
  592.             torsoswayperc = 0;
  593.         end
  594.        
  595.         torsoswayperc=clamp(torsoswayperc+0.01,0,1);
  596.        
  597.         torsosway = lerp(torsoswayorigin,0,torsoswayperc);
  598.        
  599.         if GroundHit then
  600.             speed = 0; --speed = clamp(speed-0.02,0,decayorigin);
  601.         end
  602.    
  603.        
  604.         if Turning then
  605.             local desang = math.sin(time*10);
  606.             desangmod = math.sin(time*18);
  607.             if 1-desangmod <= .1 and not stepreached then
  608.                 playsound(Step,math.random(90,100)/100,true);
  609.                 stepreached = true;
  610.             end
  611.             if desangmod <= .1 then
  612.                 stepreached = false;
  613.             end
  614.             LeftHip.MaxVelocity = 0.025;
  615.             RightHip.MaxVelocity = 0.025;
  616.             LeftHip.DesiredAngle = LockHip or desang;
  617.             RightHip.DesiredAngle = LockHip or -desang;
  618.         else
  619.             LeftHip.MaxVelocity = 0.05;
  620.             RightHip.MaxVelocity = 0.05;
  621.             LeftHip.DesiredAngle = LockHip or 0;
  622.             RightHip.DesiredAngle = LockHip or 0;
  623.         end
  624.     end
  625.  
  626.     local d = TorsoCenter.CFrame:pointToObjectSpace(Mouse.UnitRay.Origin+Mouse.UnitRay.Direction.unit*100);
  627.     local mouseX = math.atan2(d.X,-d.Z);
  628.     local mouseY =  math.asin(-d.unit.Y);
  629.     local angleY = -mouseY*2
  630.     local angleX = -mouseX
  631.  
  632.  
  633.  
  634.  
  635.    
  636.     if Looking and not Jumping then
  637.         local NewNeckC0  = CFrame.Angles(0,angleX-1.5,-angleY)--*CFrame.Angles(0,-1.5,0);
  638.         Neck.C0 = NewNeckC0;
  639.     end
  640.    
  641.     if ShootRight then
  642.      
  643.       if time-RightFlashTime>=RightFlashThresh then
  644.           RightFlashThresh = .1;
  645.           RightFlashTime = time;
  646.           RightFlashCount = RightFlashCount == 4 and 1 or RightFlashCount+1;
  647.           RightFlashes[RightFlashCount].Enabled=true;
  648.           local holepart = RightFlashes[RightFlashCount].Parent;
  649.           holepart.BrickColor = BrickColor.new("Bright yellow");
  650.           holepart.Material = "Neon";
  651.          
  652.           local ray = Ray.new(Mouse.UnitRay.Origin,Mouse.UnitRay.Direction*999);
  653.           local hit,pos = Workspace:FindPartOnRayWithIgnoreList(ray,{Mech});
  654.           if hit and hit.Parent and not hit.Parent:FindFirstChild("Humanoid") then
  655.               local bullethole = holepart:clone();
  656.               bullethole.BrickColor = BrickColor.new("Really black");
  657.               bullethole.Material = "Plastic";
  658.               game.Debris:AddItem(bullethole,10);
  659.               bullethole.Flash:Destroy();
  660.               bullethole.Mesh.Scale = Vector3.new(.2,.1,.2)
  661.               bullethole.Parent = Mech;
  662.               bullethole.Anchored = true;
  663.               bullethole.CFrame = CFrame.new(pos);
  664.           end
  665.           if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
  666.             if hit.Parent:FindFirstChild("Health") then
  667.                 hit.Parent.Health.Disabled = false;
  668.             end
  669.             hit.Parent.Humanoid:TakeDamage(10);
  670.           end
  671.           local last = RightFlashCount-1;
  672.           RightFlashes[(last==0 and 4 or last)].Enabled=false;
  673.           local lasthole = RightFlashes[(last==0 and 4 or last)].Parent;
  674.           lasthole.Material = "Plastic";
  675.           lasthole.BrickColor = BrickColor.new("Really black");
  676.       end
  677.    
  678.       RightGun.C0=RightGun.C0*CFrame.Angles(math.rad(lerp(0,100,RightGunSpeedPerc)),0,0);
  679.     else
  680.       if LastShootRight then
  681.          for _,v in pairs(RightFlashes) do
  682.            v.Enabled = false;
  683.            v.Parent.Material = "Plastic";
  684.            v.Parent.BrickColor = BrickColor.new("Really black");
  685.          end
  686.          RightFlashCount = 0;
  687.          CoolingRight = true;
  688.          RightGunSpeedPerc=0;
  689.       end
  690.       if CoolingRight then
  691.          RightGun.C0 = RightGun.C0*CFrame.Angles(math.rad(lerp(10000,0,RightGunSpeedPerc)),0,0);
  692.       end
  693.     end
  694.     if ShootLeft then
  695.        
  696.        
  697.       if time-LeftFlashTime>=LeftFlashThresh then
  698.           LeftFlashThresh = .1;
  699.           LeftFlashTime = time;
  700.           LeftFlashCount = LeftFlashCount == 4 and 1 or LeftFlashCount+1;
  701.           LeftFlashes[LeftFlashCount].Enabled=true;
  702.           local holepart = LeftFlashes[LeftFlashCount].Parent;
  703.           holepart.BrickColor = BrickColor.new("Bright yellow");
  704.           holepart.Material = "Neon";
  705.          
  706.           local ray = Ray.new(Mouse.UnitRay.Origin,Mouse.UnitRay.Direction*999);
  707.           local hit,pos = Workspace:FindPartOnRayWithIgnoreList(ray,{Mech});
  708.           if hit and hit.Parent and not hit.Parent:FindFirstChild("Humanoid") then
  709.               local bullethole = holepart:clone();
  710.               bullethole.BrickColor = BrickColor.new("Really black");
  711.               bullethole.Material = "Plastic";
  712.               game.Debris:AddItem(bullethole,10);
  713.               bullethole.Flash:Destroy();
  714.               bullethole.Mesh.Scale = Vector3.new(.2,.1,.2)
  715.               bullethole.Parent = Mech;
  716.               bullethole.Anchored = true;
  717.               bullethole.CFrame = CFrame.new(pos);
  718.           end
  719.           if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
  720.             if hit.Parent:FindFirstChild("Health") then
  721.                 hit.Parent.Health.Disabled = false;
  722.             end
  723.             hit.Parent.Humanoid:TakeDamage(10);
  724.           end
  725.           local last = LeftFlashCount-1;
  726.           LeftFlashes[(last==0 and 4 or last)].Enabled=false;
  727.           local lasthole = LeftFlashes[(last==0 and 4 or last)].Parent;
  728.           lasthole.Material = "Plastic";
  729.           lasthole.BrickColor = BrickColor.new("Really black");
  730.       end
  731.    
  732.       LeftGun.C0=LeftGun.C0*CFrame.Angles(math.rad(lerp(0,10000,LeftGunSpeedPerc)),0,0);
  733.     else
  734.       if LastShootLeft then
  735.          for _,v in pairs(LeftFlashes) do
  736.            v.Enabled = false;
  737.            v.Parent.Material = "Plastic";
  738.            v.Parent.BrickColor = BrickColor.new("Really black");
  739.          end
  740.          CoolingLeft = true;
  741.          LeftGunSpeedPerc=0;
  742.       end
  743.       if CoolingLeft then
  744.         LeftGun.C0=LeftGun.C0*CFrame.Angles(math.rad(lerp(10000,0,LeftGunSpeedPerc)),0,0);
  745.       end
  746.     end
  747.    
  748.    
  749.    
  750.    
  751.    
  752.     local dir;
  753.     if Turning then
  754.         dir=-Turning*.01;
  755.     end
  756.    
  757.     if not Flying then
  758.      TorsoCF = TorsoCenter.CFrame;
  759.      TorsoCF = TorsoCF*CFrame.new(-speed*(Walking or 1),decy/10,0)*CFrame.Angles(0,dir or torsosway/4,0);
  760.     else
  761.      TorsoCF = TorsoCenter.CFrame;
  762.      TorsoCF = CFrame.new(TorsoCF.p,TorsoCF.p+Cam.CoordinateFrame.lookVector*Vector3.new(10,10,10))*CFrame.Angles(0,math.rad(-90),0) *CFrame.new(-1,0,0)
  763.     end
  764.     TorsoCenter.CFrame = TorsoCF;
  765.  
  766.     lastwalking = Walking;
  767.     LastSprinting = Sprinting;
  768.     lastsway = swaygoal;
  769.     LastJumping = Jumping;
  770.     LastLooking = Looking;
  771.     LastNeckXYZ = Vector3.new(Neck.C0:toEulerAnglesXYZ())*Vector3.new(0,1,0);
  772.    
  773.     LastShootRight = ShootRight;
  774.     LastShootLeft = ShootLeft;
  775.     LastGroundHit = GroundHit
  776.     LastThrusterPlaying = ThrusterPlaying;
  777.     LastLeftRocketPoint = LeftRocketPoint;
  778.     LastRightRocketPoint = RightRocketPoint;
  779. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement