Вот простой пример скрипта для полёта в Roblox. Этот скрипт позволяет игроку включать и выключать режим полёта при нажатии клавиши (например, "F"). Скрипт должен быть помешён в LocalScript внутри StarterPlayerScripts.
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local player = game.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 = 50
local flyVelocity = Instance.new("BodyVelocity")
flyVelocity.MaxForce = Vector3.new(1e5, 1e5, 1e5)
flyVelocity.Velocity = Vector3.new(0,0,0)
flyVelocity.Parent = rootPart
local flyDirection = Vector3.new(0,0,0)
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.F then
flying = not flying
if flying then
humanoid.PlatformStand = true
else
humanoid.PlatformStand = false
flyVelocity.Velocity = Vector3.new(0,0,0)
end
end
end)
UserInputService.InputChanged:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.UserInputType == Enum.UserInputType.MouseMovement then
-- Можно добавить управление поворотом камеры при полёте, если нужно
end
end)
RunService.RenderStepped:Connect(function(deltaTime)
if flying then
local moveDirection = Vector3.new(0,0,0)
if UserInputService:IsKeyDown(Enum.KeyCode.W) then
moveDirection = moveDirection + workspace.CurrentCamera.CFrame.LookVector
end
if UserInputService:IsKeyDown(Enum.KeyCode.S) then
moveDirection = moveDirection - workspace.CurrentCamera.CFrame.LookVector
end
if UserInputService:IsKeyDown(Enum.KeyCode.A) then
moveDirection = moveDirection - workspace.CurrentCamera.CFrame.RightVector
end
if UserInputService:IsKeyDown(Enum.KeyCode.D) then
moveDirection = moveDirection + workspace.CurrentCamera.CFrame.RightVector
end
if UserInputService:IsKeyDown(Enum.KeyCode.Space) then
moveDirection = moveDirection + Vector3.new(0,1,0)
end
if UserInputService:IsKeyDown(Enum.KeyCode.LeftControl) then
moveDirection = moveDirection - Vector3.new(0,1,0)
end
if moveDirection.Magnitude > 0 then
moveDirection = moveDirection.Unit
end
flyVelocity.Velocity = moveDirection * flySpeed
end
end)
Как использовать:
- Создайте
LocalScript в StarterPlayerScripts.
- Вставьте туда этот код.
- Запустите игру.
- Нажмите клавишу "F" чтобы включить/отключить полёт.
- Управляйте полётом с помощью клавиш W,A,S,D (вперёд, влево, назад, вправо), Space (вверх), Left Control (вниз).
Если нужно, могу помочь добавить новые возможности или адаптировать скрипт под конкретные задачи.