Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local settings = {
- speed = 2,
- acceleration = 0.5;
- }
- local mouse = game.Players.LocalPlayer:GetMouse()
- local camera = workspace.Camera
- local RS = game:GetService("RunService").RenderStepped
- local player = game.Players.LocalPlayer
- local pressedKeys = {}
- local touchedParts = {}
- local flying = false
- function connectTouchEvent(part)
- if part:FindFirstChild("HasTouchEvent") == nil then
- part.Touched:connect(function(partTouched)
- if partTouched.CanCollide == true and flying == true then
- table.insert(touchedParts, partTouched)
- partTouched.CanCollide = false
- end
- end)
- Instance.new("BoolValue", part).Name = "HasTouchEvent"
- end
- end
- local speedModifier = 1
- local acceleration = 0.008
- local currentPos = Vector3.new(0, 0, 0)
- local bodyForcePosition = nil
- mouse.KeyDown:connect(function(key)
- local char = player.Character
- if char then
- local head = char:FindFirstChild("Head")
- pressedKeys[string.lower(tostring(key))] = string.lower(tostring(key))
- if string.lower(tostring(key)) == "f" and head then
- if flying == true then
- flying = false
- for _,c in pairs(char:GetChildren()) do
- if c.ClassName == "Part" then
- c.RotVelocity = Vector3.new(0, 0, 0)
- c.Velocity = Vector3.new(0, 0, 0)
- c.CustomPhysicalProperties = PhysicalProperties.new(Enum.Material.Plastic)
- end
- end
- if bodyForcePosition then
- bodyForcePosition.Parent = nil
- end
- for _,part in pairs(touchedParts) do
- part.CanCollide = true
- end
- touchedParts = {}
- elseif flying == false then
- currentPos = head.Position
- if bodyForcePosition then
- bodyForcePosition.Parent = head
- end
- flying = true
- for _,c in pairs(char:GetChildren()) do
- if c.ClassName == "Part" then
- connectTouchEvent(c)
- c.CustomPhysicalProperties = PhysicalProperties.new(100, 2, 0)
- end
- end
- end
- end
- end
- end)
- mouse.KeyUp:connect(function(key)
- pressedKeys[string.lower(tostring(key))] = nil
- end)
- local char = nil
- local head = nil
- local cameraLookVector = camera.CFrame.LookVector
- local cameraRightVector = camera.CFrame.RightVector
- local cameraUpVector = camera.CFrame.UpVector
- local pressingKey = false
- RS:connect(function()
- char = player.Character
- if char then
- head = char:FindFirstChild("Head")
- if flying and head then
- cameraLookVector = camera.CFrame.LookVector
- cameraRightVector = camera.CFrame.RightVector
- cameraUpVector = camera.CFrame.UpVector
- pressingKey = false
- for _,pressedKey in pairs(pressedKeys) do
- if string.lower(tostring(pressedKey)) == "w" then
- currentPos = currentPos + cameraLookVector*speedModifier
- pressingKey = true
- elseif string.lower(tostring(pressedKey)) == "s" then
- currentPos = currentPos + cameraLookVector*-speedModifier
- pressingKey = true
- elseif string.lower(tostring(pressedKey)) == "a" then
- currentPos = currentPos + cameraRightVector*-speedModifier
- pressingKey = true
- elseif string.lower(tostring(pressedKey)) == "d" then
- currentPos = currentPos + cameraRightVector*speedModifier
- pressingKey = true
- elseif string.lower(tostring(pressedKey)) == "e" then
- --currentPos = currentPos + cameraUpVector*speedModifier
- --pressingKey = true
- elseif string.lower(tostring(pressedKey)) == "q" then
- --currentPos = currentPos + cameraUpVector*-speedModifier
- --pressingKey = true
- end
- end
- bodyForcePosition = head:FindFirstChild("FlyForce") or Instance.new("BodyPosition", head)
- bodyForcePosition.Position = currentPos
- bodyForcePosition.Name = "FlyForce"
- bodyForcePosition.P = 100000
- bodyForcePosition.D = 500
- bodyForcePosition.MaxForce = Vector3.new(4000000000, 4000000000, 4000000000)
- if pressingKey then
- speedModifier = speedModifier + settings.acceleration
- else
- speedModifier = settings.speed
- end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement