Вот простой пример скрипта на Lua для инструмента Fly в Roblox. Этот скрипт позволяет игроку включать и выключать режим полёта нажатием клавиши (например, клавиши "F").
lua
-- Скрипт для полёта (Fly) в Roblox
-- Поместите этот скрипт в 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 velocity = Vector3.new(0,0,0)
local bodyVelocity
-- Функция включения полёта
local function startFly()
if flying then return end
flying = true
bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.MaxForce = Vector3.new(1e5, 1e5, 1e5)
bodyVelocity.P = 1e4
bodyVelocity.Velocity = Vector3.new(0,0,0)
bodyVelocity.Parent = rootPart
humanoid.PlatformStand = true
end
-- Функция выключения полёта
local function stopFly()
if not flying then return end
flying = false
if bodyVelocity then
bodyVelocity:Destroy()
bodyVelocity = nil
end
humanoid.PlatformStand = false
end
-- Обработка нажатия клавиш
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.F then -- Клавиша "F" для включения/выключения полёта
if flying then
stopFly()
else
startFly()
end
end
end)
-- Обновление скорости полёта каждый кадр
RunService.RenderStepped:Connect(function()
if flying and bodyVelocity then
local moveDirection = Vector3.new(0,0,0)
local camera = workspace.CurrentCamera
local forward = camera.CFrame.LookVector
local right = camera.CFrame.RightVector
if UserInputService:IsKeyDown(Enum.KeyCode.W) then
moveDirection = moveDirection + forward
end
if UserInputService:IsKeyDown(Enum.KeyCode.S) then
moveDirection = moveDirection - forward
end
if UserInputService:IsKeyDown(Enum.KeyCode.A) then
moveDirection = moveDirection - right
end
if UserInputService:IsKeyDown(Enum.KeyCode.D) then
moveDirection = moveDirection + right
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
moveDirection = moveDirection.Unit
if moveDirection.Magnitude > 0 then
bodyVelocity.Velocity = moveDirection * flySpeed
else
bodyVelocity.Velocity = Vector3.new(0,0,0)
end
end
end)
Как использовать:
Создайте LocalScript в StarterPlayer > StarterPlayerScripts.
Вставьте туда этот код.
Запустите игру, чтобы проверить. Нажатием клавиши F вы включаете или выключаете режим полёта.
Управление полётом осуществляется клавишами W, A, S, D для движения и Space/LeftControl для подъёма/опускания.