uoryetwq

f fly

Mar 13th, 2025
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local UserInputService = game:GetService("UserInputService")
  3. local RunService = game:GetService("RunService")
  4.  
  5. local Player = Players.LocalPlayer
  6. local Character = Player.Character or Player.CharacterAdded:Wait()
  7. local Humanoid = Character:WaitForChild("Humanoid")
  8. local RootPart = Character:WaitForChild("HumanoidRootPart")
  9.  
  10. local flying = false
  11. local flySpeed = 200 -- 비행 속도 설정 (여기서 속도 변경)
  12. local velocity = Vector3.new(0, 0, 0)
  13.  
  14. -- 입력된 방향 저장
  15. local movement = {
  16. Forward = 0,
  17. Right = 0
  18. }
  19.  
  20. -- 비행 시작 함수
  21. local function StartFly()
  22. if not flying then
  23. flying = true
  24.  
  25. -- 중력 제거
  26. local bodyGyro = Instance.new("BodyGyro", RootPart)
  27. bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
  28. bodyGyro.P = 9e4
  29. bodyGyro.CFrame = RootPart.CFrame
  30.  
  31. local bodyVelocity = Instance.new("BodyVelocity", RootPart)
  32. bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  33.  
  34. -- 비행 로직 실행
  35. RunService.RenderStepped:Connect(function()
  36. if flying and RootPart then
  37. -- 현재 바라보는 방향 기준으로 이동
  38. local camera = workspace.CurrentCamera
  39. local moveDirection = (camera.CFrame.LookVector * movement.Forward) + (camera.CFrame.RightVector * movement.Right)
  40. velocity = moveDirection.Unit * flySpeed
  41. if moveDirection.Magnitude == 0 then
  42. velocity = Vector3.new(0, 0, 0)
  43. end
  44. bodyVelocity.Velocity = velocity
  45. end
  46. end)
  47. end
  48. end
  49.  
  50. -- 비행 종료 함수
  51. local function StopFly()
  52. flying = false
  53. for _, obj in pairs(RootPart:GetChildren()) do
  54. if obj:IsA("BodyVelocity") or obj:IsA("BodyGyro") then
  55. obj:Destroy()
  56. end
  57. end
  58. end
  59.  
  60. -- 방향 입력 감지
  61. UserInputService.InputBegan:Connect(function(input, gameProcessed)
  62. if not gameProcessed then
  63. if input.KeyCode == Enum.KeyCode.F then
  64. if flying then
  65. StopFly()
  66. else
  67. StartFly()
  68. end
  69. elseif input.KeyCode == Enum.KeyCode.W then
  70. movement.Forward = 1
  71. elseif input.KeyCode == Enum.KeyCode.S then
  72. movement.Forward = -1
  73. elseif input.KeyCode == Enum.KeyCode.A then
  74. movement.Right = -1
  75. elseif input.KeyCode == Enum.KeyCode.D then
  76. movement.Right = 1
  77. end
  78. end
  79. end)
  80.  
  81. UserInputService.InputEnded:Connect(function(input, gameProcessed)
  82. if not gameProcessed then
  83. if input.KeyCode == Enum.KeyCode.W or input.KeyCode == Enum.KeyCode.S then
  84. movement.Forward = 0
  85. elseif input.KeyCode == Enum.KeyCode.A or input.KeyCode == Enum.KeyCode.D then
  86. movement.Right = 0
  87. end
  88. end
  89. end)
  90.  
Advertisement
Add Comment
Please, Sign In to add comment