Advertisement
Guest User

Untitled

a guest
Aug 17th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.97 KB | None | 0 0
  1. local RunService = game:GetService("RunService")
  2. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  3. local UserInputService = game:GetService("UserInputService")
  4. local Up = false
  5. local Down = false
  6. local w,a,s,d = false,false,false,false
  7. script:WaitForChild ("Vehicle")
  8. local vehicle = script.Vehicle
  9. --local bodyGyro = workspace.Ships.DarkGreenShip.ShipModel.ShipHull:WaitForChild("BodyGyro")
  10. --//Vehicle Settings
  11. local moveMax = 90
  12. local rotateMax = 1
  13. local upDownMax = 40
  14. --Accelerate is the incerement of SPEED increase per second when a key is pressed
  15. local moveAccelerate = 3
  16. local rotateAccelerate = .5
  17. local upDownAccelerate = 10
  18. --Decay is the increment of SPEED decrease per second when no key is pressed
  19. local moveDecay = .8
  20. local rotateDecay = .6
  21. local upDownDecay = .6
  22. --Set these up for use later
  23. local moveSpeed = 0 --do not change
  24. local rotateSpeed = 0 --do not change
  25. local upDownSpeed = 0 --do not change
  26. --local pitch = 0 --do not change
  27. --local yaw = 0 --do not change
  28. --local roll = 0 --do not change
  29.  
  30.  
  31.  
  32. --// Control Inputs
  33. local keyE = nil
  34. local keyQ = nil
  35. local keyW = nil
  36. local keyS = nil
  37. local keyA = nil
  38. local keyD = nil
  39. function KeyPress(key)
  40.         if key.KeyCode == Enum.KeyCode.E then
  41.             keyE = true
  42.         end
  43.         if key.KeyCode == Enum.KeyCode.Q then
  44.             keyQ = true
  45.         end
  46.         if key.KeyCode == Enum.KeyCode.W then
  47.             keyW = true
  48.         end
  49.         if key.KeyCode == Enum.KeyCode.S then
  50.             keyS = true
  51.         end
  52.         if key.KeyCode == Enum.KeyCode.A then
  53.             keyA = true
  54.         end
  55.         if key.KeyCode == Enum.KeyCode.D then
  56.             keyD = true
  57.         end
  58. end
  59.  
  60. function KeyRelease(key)
  61.         if key.KeyCode == Enum.KeyCode.E then
  62.             keyE = false
  63.         end
  64.         if key.KeyCode == Enum.KeyCode.Q then
  65.             keyQ = false
  66.         end
  67.         if key.KeyCode == Enum.KeyCode.W then
  68.             keyW = false
  69.         end
  70.         if key.KeyCode == Enum.KeyCode.S then
  71.             keyS = false
  72.         end
  73.         if key.KeyCode == Enum.KeyCode.A then
  74.             keyA = false
  75.         end
  76.         if key.KeyCode == Enum.KeyCode.D then
  77.             keyD = false
  78.         end
  79. end
  80.  
  81. UserInputService.InputBegan:Connect(KeyPress)
  82. UserInputService.InputEnded:Connect(KeyRelease)
  83.  
  84. function ControlSpeed()
  85.     --UP and DOWN
  86.     if keyE and upDownSpeed < upDownMax then upDownSpeed = upDownSpeed + upDownAccelerate end
  87.     if keyQ and upDownSpeed > -upDownMax then upDownSpeed = upDownSpeed + -upDownAccelerate end
  88.     --if keyE then pitch = -100 end
  89.     --if keyQ then pitch = 100 end
  90.     --UP and DOWN
  91.     if keyW and moveSpeed < moveMax then moveSpeed = moveSpeed + moveAccelerate end
  92.     if keyS and moveSpeed > -moveMax then moveSpeed = moveSpeed + -moveAccelerate end
  93.     --if not keyW or keyS then moveSpeed = 0 end
  94.     --LEFT and RIGHT
  95.     if keyA then rotateSpeed = rotateSpeed + rotateAccelerate  end
  96.  
  97.     if keyD then rotateSpeed = rotateSpeed + -rotateAccelerate  end
  98.  
  99.     if rotateSpeed > rotateMax then rotateSpeed = rotateMax end
  100.     if rotateSpeed < -rotateMax then rotateSpeed = -rotateMax end
  101.     --if keyA then roll = -100 end
  102.     --if keyD then roll = 100 end
  103.     --if keyA then yaw = 1 end
  104.     --if keyD then yaw = -1 end
  105.     --if not keyA or keyD then rotateSpeed = 0 end
  106. end
  107.  
  108. function DecaySpeed() -- This function check to see if the key is not pressed, then decays the appropriate speeds
  109.     if not keyW then
  110.         if not keyS then
  111.             if moveSpeed > 0 then moveSpeed = moveSpeed * moveDecay end
  112.             if moveSpeed < 0 then moveSpeed = moveSpeed * moveDecay end
  113.             if moveSpeed < .1 and moveSpeed > -.1 then moveSpeed = 0 end
  114.         end
  115.     end
  116.  
  117.     if not keyD then
  118.         if not keyA then       
  119.             if rotateSpeed > 0 then rotateSpeed = rotateSpeed * rotateDecay end
  120.             if rotateSpeed < 0 then rotateSpeed = rotateSpeed * rotateDecay end
  121.             if rotateSpeed < .1 and rotateSpeed > -.1 then rotateSpeed = 0 end
  122.             --roll = 0
  123.             --yaw = 0
  124.         end
  125.     end
  126.  
  127.     if not keyQ then
  128.         if not keyE then   
  129.             if upDownSpeed > 0 then upDownSpeed = upDownSpeed * upDownDecay end
  130.             if upDownSpeed < 0 then upDownSpeed = upDownSpeed * upDownDecay end
  131.             if upDownSpeed < .001 and upDownSpeed > -.001 then upDownSpeed = 0 end
  132.             --pitch = 0
  133.         end
  134.     end
  135. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement