Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local RunService = game:GetService("RunService")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local UserInputService = game:GetService("UserInputService")
- local Up = false
- local Down = false
- local w,a,s,d = false,false,false,false
- script:WaitForChild ("Vehicle")
- local vehicle = script.Vehicle
- --local bodyGyro = workspace.Ships.DarkGreenShip.ShipModel.ShipHull:WaitForChild("BodyGyro")
- --//Vehicle Settings
- local moveMax = 90
- local rotateMax = 1
- local upDownMax = 40
- --Accelerate is the incerement of SPEED increase per second when a key is pressed
- local moveAccelerate = 3
- local rotateAccelerate = .5
- local upDownAccelerate = 10
- --Decay is the increment of SPEED decrease per second when no key is pressed
- local moveDecay = .8
- local rotateDecay = .6
- local upDownDecay = .6
- --Set these up for use later
- local moveSpeed = 0 --do not change
- local rotateSpeed = 0 --do not change
- local upDownSpeed = 0 --do not change
- --local pitch = 0 --do not change
- --local yaw = 0 --do not change
- --local roll = 0 --do not change
- --// Control Inputs
- local keyE = nil
- local keyQ = nil
- local keyW = nil
- local keyS = nil
- local keyA = nil
- local keyD = nil
- function KeyPress(key)
- if key.KeyCode == Enum.KeyCode.E then
- keyE = true
- end
- if key.KeyCode == Enum.KeyCode.Q then
- keyQ = true
- end
- if key.KeyCode == Enum.KeyCode.W then
- keyW = true
- end
- if key.KeyCode == Enum.KeyCode.S then
- keyS = true
- end
- if key.KeyCode == Enum.KeyCode.A then
- keyA = true
- end
- if key.KeyCode == Enum.KeyCode.D then
- keyD = true
- end
- end
- function KeyRelease(key)
- if key.KeyCode == Enum.KeyCode.E then
- keyE = false
- end
- if key.KeyCode == Enum.KeyCode.Q then
- keyQ = false
- end
- if key.KeyCode == Enum.KeyCode.W then
- keyW = false
- end
- if key.KeyCode == Enum.KeyCode.S then
- keyS = false
- end
- if key.KeyCode == Enum.KeyCode.A then
- keyA = false
- end
- if key.KeyCode == Enum.KeyCode.D then
- keyD = false
- end
- end
- UserInputService.InputBegan:Connect(KeyPress)
- UserInputService.InputEnded:Connect(KeyRelease)
- function ControlSpeed()
- --UP and DOWN
- if keyE and upDownSpeed < upDownMax then upDownSpeed = upDownSpeed + upDownAccelerate end
- if keyQ and upDownSpeed > -upDownMax then upDownSpeed = upDownSpeed + -upDownAccelerate end
- --if keyE then pitch = -100 end
- --if keyQ then pitch = 100 end
- --UP and DOWN
- if keyW and moveSpeed < moveMax then moveSpeed = moveSpeed + moveAccelerate end
- if keyS and moveSpeed > -moveMax then moveSpeed = moveSpeed + -moveAccelerate end
- --if not keyW or keyS then moveSpeed = 0 end
- --LEFT and RIGHT
- if keyA then rotateSpeed = rotateSpeed + rotateAccelerate end
- if keyD then rotateSpeed = rotateSpeed + -rotateAccelerate end
- if rotateSpeed > rotateMax then rotateSpeed = rotateMax end
- if rotateSpeed < -rotateMax then rotateSpeed = -rotateMax end
- --if keyA then roll = -100 end
- --if keyD then roll = 100 end
- --if keyA then yaw = 1 end
- --if keyD then yaw = -1 end
- --if not keyA or keyD then rotateSpeed = 0 end
- end
- function DecaySpeed() -- This function check to see if the key is not pressed, then decays the appropriate speeds
- if not keyW then
- if not keyS then
- if moveSpeed > 0 then moveSpeed = moveSpeed * moveDecay end
- if moveSpeed < 0 then moveSpeed = moveSpeed * moveDecay end
- if moveSpeed < .1 and moveSpeed > -.1 then moveSpeed = 0 end
- end
- end
- if not keyD then
- if not keyA then
- if rotateSpeed > 0 then rotateSpeed = rotateSpeed * rotateDecay end
- if rotateSpeed < 0 then rotateSpeed = rotateSpeed * rotateDecay end
- if rotateSpeed < .1 and rotateSpeed > -.1 then rotateSpeed = 0 end
- --roll = 0
- --yaw = 0
- end
- end
- if not keyQ then
- if not keyE then
- if upDownSpeed > 0 then upDownSpeed = upDownSpeed * upDownDecay end
- if upDownSpeed < 0 then upDownSpeed = upDownSpeed * upDownDecay end
- if upDownSpeed < .001 and upDownSpeed > -.001 then upDownSpeed = 0 end
- --pitch = 0
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement