Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.93 KB | None | 0 0
  1.  
  2. -- Services
  3. local UserInputService = game:GetService("UserInputService")
  4. local Players = game:GetService("Players")
  5.  
  6. -- Variables
  7. local Helicopter = script.Parent.Parent.Parent
  8. local Heli = Helicopter.Helicopter
  9. local GyroScope = script.Parent
  10. local Thrust = Heli:FindFirstChild("BodyThrust")
  11. local Reaction = Heli:FindFirstChild("BodyReaction")
  12. local Force = Heli:FindFirstChild("BodyVelocity")
  13. local AngularVelocity = Heli:FindFirstChild("BodyAngularVelocity")
  14.  
  15. -- Physics Variables
  16. local m = Heli:GetMass()
  17. local g =  workspace.Gravity
  18. local cf = CFrame.new()
  19. local vector = Vector3.new()
  20. local MaxForce = m^2*4
  21.  
  22. -- Other
  23. local enum = Enum.KeyCode
  24. local turnSpeedPerSecond = 1
  25.  
  26. local turnAngle = 0
  27.  
  28. -- This is like loop and runs every Frame
  29. game:GetService("RunService").Stepped:Connect(function (timeSinceLastFrame)
  30.    
  31.  
  32.     local T = UserInputService:IsKeyDown(enum.T) and 1 or 0
  33.     local G = UserInputService:IsKeyDown(enum.G) and 1 or 0
  34.     local R = UserInputService:IsKeyDown(enum.R) and 1 or 0
  35.     local Y = UserInputService:IsKeyDown(enum.Y) and 1 or 0
  36.     local F = UserInputService:IsKeyDown(enum.F) and 1 or 0
  37.     local H = UserInputService:IsKeyDown(enum.H) and 1 or 0
  38.     local J = UserInputService:IsKeyDown(enum.J) and 1 or 0
  39.     local LeftShift = UserInputService:IsKeyDown(enum.LeftShift) and 1 or 0
  40.    
  41.     turnAngle = turnAngle + (F - H) * turnSpeedPerSecond * timeSinceLastFrame
  42.     local direction = Vector3.new(R - Y, J - LeftShift, T - G).Unit
  43.     local m = direction.Magnitude
  44.    
  45.     -- Reaction Force
  46.     Thrust.Force = Vector3.new(0, 9.01*m*g, 0)
  47.     Reaction.Force = -Vector3.new(0, 8*m*g, 0)
  48.    
  49.     -- Friction/Resistance
  50.     Heli.Velocity = Heli.Velocity - Heli.Velocity/10
  51.    
  52.     -- adding Force/CFrame values
  53.     GyroScope.CFrame = CFrame.Angles(0, math.rad(turnAngle), 0)
  54.    
  55.     if m == m then
  56.        
  57.         Force.Velocity = (CFrame.Angles(0, turnAngle, 0) * CFrame.new(direction)).p
  58.     else
  59.        
  60.         Force.Velocity = Vector3.new()
  61.     end
  62.    
  63. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement