Advertisement
HowToRoblox

SpaceshipController

Jun 20th, 2021
2,330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.48 KB | None | 0 0
  1. local hum = script.Parent:WaitForChild("Humanoid")
  2.  
  3.  
  4. local seat = nil
  5.  
  6.  
  7. hum.Seated:Connect(function(active, seatPart)
  8.    
  9.     seat = seatPart
  10. end)
  11.  
  12.  
  13. local w = false
  14. local s = false
  15.  
  16.  
  17. game:GetService("UserInputService").InputBegan:Connect(function(inp, processed)
  18.    
  19.     if processed then return end
  20.    
  21.     if inp.KeyCode == Enum.KeyCode.W then w = true end
  22.     if inp.KeyCode == Enum.KeyCode.S then s = true end
  23. end)
  24.  
  25. game:GetService("UserInputService").InputEnded:Connect(function(inp)
  26.  
  27.     if inp.KeyCode == Enum.KeyCode.W then w = false end
  28.     if inp.KeyCode == Enum.KeyCode.S then s = false end
  29. end)
  30.  
  31.  
  32. local camera = workspace.CurrentCamera
  33.  
  34. local mouse = game.Players.LocalPlayer:GetMouse()
  35.  
  36.  
  37. game:GetService("RunService").RenderStepped:Connect(function()
  38.    
  39.     if seat then
  40.        
  41.        
  42.         camera.CameraType = Enum.CameraType.Scriptable
  43.        
  44.         camera.CFrame = seat.Parent.Camera.CFrame * CFrame.Angles(
  45.                 math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -20),
  46.                 math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -20),
  47.                 0
  48.             )
  49.        
  50.        
  51.         seat.BodyGyro.CFrame = CFrame.new(seat.Parent.Body.Position, mouse.Hit.LookVector * 1000)
  52.        
  53.        
  54.         if w then
  55.            
  56.             seat.BodyVelocity.Velocity = seat.CFrame.LookVector * 100
  57.            
  58.            
  59.         elseif s then
  60.            
  61.             seat.BodyVelocity.Velocity = seat.CFrame.LookVector * -100
  62.            
  63.            
  64.         else
  65.             seat.BodyVelocity.Velocity = Vector3.new(0, 0, 0)
  66.         end
  67.        
  68.        
  69.     else
  70.         camera.CameraType = Enum.CameraType.Custom
  71.     end
  72. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement