Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local UserInputService = game:GetService("UserInputService")
- local RunService = game:GetService("RunService")
- local Player = Players.LocalPlayer
- local Character = Player.Character or Player.CharacterAdded:Wait()
- local Humanoid = Character:WaitForChild("Humanoid")
- local RootPart = Character:WaitForChild("HumanoidRootPart")
- local flying = false
- local flySpeed = 200 -- 비행 속도 설정 (여기서 속도 변경)
- local velocity = Vector3.new(0, 0, 0)
- -- 입력된 방향 저장
- local movement = {
- Forward = 0,
- Right = 0
- }
- -- 비행 시작 함수
- local function StartFly()
- if not flying then
- flying = true
- -- 중력 제거
- local bodyGyro = Instance.new("BodyGyro", RootPart)
- bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
- bodyGyro.P = 9e4
- bodyGyro.CFrame = RootPart.CFrame
- local bodyVelocity = Instance.new("BodyVelocity", RootPart)
- bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
- -- 비행 로직 실행
- RunService.RenderStepped:Connect(function()
- if flying and RootPart then
- -- 현재 바라보는 방향 기준으로 이동
- local camera = workspace.CurrentCamera
- local moveDirection = (camera.CFrame.LookVector * movement.Forward) + (camera.CFrame.RightVector * movement.Right)
- velocity = moveDirection.Unit * flySpeed
- if moveDirection.Magnitude == 0 then
- velocity = Vector3.new(0, 0, 0)
- end
- bodyVelocity.Velocity = velocity
- end
- end)
- end
- end
- -- 비행 종료 함수
- local function StopFly()
- flying = false
- for _, obj in pairs(RootPart:GetChildren()) do
- if obj:IsA("BodyVelocity") or obj:IsA("BodyGyro") then
- obj:Destroy()
- end
- end
- end
- -- 방향 입력 감지
- UserInputService.InputBegan:Connect(function(input, gameProcessed)
- if not gameProcessed then
- if input.KeyCode == Enum.KeyCode.F then
- if flying then
- StopFly()
- else
- StartFly()
- end
- elseif input.KeyCode == Enum.KeyCode.W then
- movement.Forward = 1
- elseif input.KeyCode == Enum.KeyCode.S then
- movement.Forward = -1
- elseif input.KeyCode == Enum.KeyCode.A then
- movement.Right = -1
- elseif input.KeyCode == Enum.KeyCode.D then
- movement.Right = 1
- end
- end
- end)
- UserInputService.InputEnded:Connect(function(input, gameProcessed)
- if not gameProcessed then
- if input.KeyCode == Enum.KeyCode.W or input.KeyCode == Enum.KeyCode.S then
- movement.Forward = 0
- elseif input.KeyCode == Enum.KeyCode.A or input.KeyCode == Enum.KeyCode.D then
- movement.Right = 0
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment