Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Services
- local UserInputService = game:GetService("UserInputService")
- local Players = game:GetService("Players")
- -- Variables
- local Helicopter = script.Parent.Parent.Parent
- local Heli = Helicopter.Helicopter
- local GyroScope = script.Parent
- local Thrust = Heli:FindFirstChild("BodyThrust")
- local Reaction = Heli:FindFirstChild("BodyReaction")
- local Force = Heli:FindFirstChild("BodyVelocity")
- local AngularVelocity = Heli:FindFirstChild("BodyAngularVelocity")
- -- Physics Variables
- local m = Heli:GetMass()
- local g = workspace.Gravity
- local cf = CFrame.new()
- local vector = Vector3.new()
- local MaxForce = m^2*4
- -- Other
- local enum = Enum.KeyCode
- local turnSpeedPerSecond = 1
- local turnAngle = 0
- -- This is like loop and runs every Frame
- game:GetService("RunService").Stepped:Connect(function (timeSinceLastFrame)
- local T = UserInputService:IsKeyDown(enum.T) and 1 or 0
- local G = UserInputService:IsKeyDown(enum.G) and 1 or 0
- local R = UserInputService:IsKeyDown(enum.R) and 1 or 0
- local Y = UserInputService:IsKeyDown(enum.Y) and 1 or 0
- local F = UserInputService:IsKeyDown(enum.F) and 1 or 0
- local H = UserInputService:IsKeyDown(enum.H) and 1 or 0
- local J = UserInputService:IsKeyDown(enum.J) and 1 or 0
- local LeftShift = UserInputService:IsKeyDown(enum.LeftShift) and 1 or 0
- turnAngle = turnAngle + (F - H) * turnSpeedPerSecond * timeSinceLastFrame
- local direction = Vector3.new(R - Y, J - LeftShift, T - G).Unit
- local m = direction.Magnitude
- -- Reaction Force
- Thrust.Force = Vector3.new(0, 9.01*m*g, 0)
- Reaction.Force = -Vector3.new(0, 8*m*g, 0)
- -- Friction/Resistance
- Heli.Velocity = Heli.Velocity - Heli.Velocity/10
- -- adding Force/CFrame values
- GyroScope.CFrame = CFrame.Angles(0, math.rad(turnAngle), 0)
- if m == m then
- Force.Velocity = (CFrame.Angles(0, turnAngle, 0) * CFrame.new(direction)).p
- else
- Force.Velocity = Vector3.new()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement