Конечно! Вот простой пример скрипта на Lua, который позволит вашему персонажу летать. Предполагая, что вы используете Roblox, вот универсальный скрипт для полёта:
-- Скрипт для полёта в Roblox на Lua
-- Поместите этот скрипт в LocalScript, например, в StarterPlayerScripts
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 humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local flying = false
local speed = 50 -- скорость полёта
local velocity = Vector3.new(0, 0, 0)
-- Создаём BodyVelocity для управления движением
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.MaxForce = Vector3.new(0, 0, 0)
bodyVelocity.Parent = humanoidRootPart
-- Обработчик нажатия клавиш
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.F then
flying = not flying
if flying then
bodyVelocity.MaxForce = Vector3.new(1e5, 1e5, 1e5)
else
bodyVelocity.MaxForce = Vector3.new(0, 0, 0)
bodyVelocity.Velocity = Vector3.new(0,0,0)
end
end
end)
-- Обновляем направление движения в зависимости от нажатых клавиш
RunService.RenderStepped:Connect(function()
if not flying then return end
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 * speed
else
moveDirection = Vector3.new(0,0,0)
end
bodyVelocity.Velocity = moveDirection
end)
Как использовать:
- Создайте LocalScript в
StarterPlayerScripts.
- Вставьте туда данный код.
- Запустите игру.
- Нажмите клавишу
F чтобы включить или выключить режим полёта.
- Управляйте движением с помощью WASD (вперёд, назад, влево, вправо),
Space — вверх, Left Control — вниз.
Если нужна другая платформа или среда, уточните, и я помогу адаптировать.