Advertisement
HowToRoblox

HelicopterController

Apr 24th, 2021
3,578
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.06 KB | None | 0 0
  1. local char = script.Parent
  2. local humanoid = char:WaitForChild("Humanoid")
  3.  
  4. local cas = game:GetService("ContextActionService")
  5.  
  6. local seat = nil
  7.  
  8. local heightIncrease = 0
  9. local rotation = 0
  10. local movement = 0
  11.  
  12.  
  13. function height(actionName, actionState)
  14.    
  15.     if actionName == "Up" and actionState == Enum.UserInputState.Begin then
  16.         heightIncrease = 10
  17.        
  18.     elseif actionName == "Down" and actionState == Enum.UserInputState.Begin then
  19.         heightIncrease = -10
  20.        
  21.     else
  22.         heightIncrease = 0
  23.     end
  24. end
  25.  
  26. function rotate(actionName, actionState)
  27.    
  28.     if actionName == "Left" and actionState == Enum.UserInputState.Begin then
  29.         rotation = -10
  30.        
  31.     elseif actionName == "Right" and actionState == Enum.UserInputState.Begin then
  32.         rotation = 10
  33.        
  34.     else
  35.         rotation = 0
  36.     end
  37. end
  38.  
  39. function move(actionName, actionState)
  40.    
  41.     if actionName == "Forward" and actionState == Enum.UserInputState.Begin then
  42.         movement = 20
  43.  
  44.     elseif actionName == "Backward" and actionState == Enum.UserInputState.Begin then
  45.         movement = -20
  46.  
  47.     else
  48.         movement = 0
  49.     end
  50. end
  51.  
  52.  
  53. humanoid.Seated:Connect(function(active, seatPart)
  54.    
  55.     if active and seatPart:IsA("VehicleSeat") and seatPart.Parent.Name == "Helicopter" then
  56.        
  57.        
  58.         cas:BindAction("Up", height, false, "e")
  59.         cas:BindAction("Down", height, false, "q")
  60.         cas:BindAction("Left", rotate, false, "a")
  61.         cas:BindAction("Right", rotate, false, "d")
  62.         cas:BindAction("Forward", move, false, "w")
  63.         cas:BindAction("Backward", move, false, "s")
  64.        
  65.         seat = seatPart
  66.        
  67.        
  68.     elseif not active then
  69.        
  70.         cas:UnbindAction("Up")
  71.         cas:UnbindAction("Down")
  72.         cas:UnbindAction("Left")
  73.         cas:UnbindAction("Right")
  74.         cas:UnbindAction("Forward")
  75.         cas:UnbindAction("Backward")
  76.        
  77.         seat = nil
  78.     end
  79. end)
  80.  
  81.  
  82. game:GetService("RunService").RenderStepped:Connect(function()
  83.    
  84.     if seat then
  85.        
  86.        
  87.         local bp = seat.BodyPosition
  88.         local bg = seat.BodyGyro
  89.        
  90.         bp.Position = seat.Position + Vector3.new(0, heightIncrease, 0) + (seat.CFrame.LookVector * movement)
  91.         bg.CFrame = seat.CFrame * CFrame.Angles(0, rotation, 0)
  92.     end
  93. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement