Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fly #302

Open
aap-bot opened this issue Oct 3, 2024 · 0 comments
Open

Fly #302

aap-bot opened this issue Oct 3, 2024 · 0 comments

Comments

@aap-bot
Copy link

aap-bot commented Oct 3, 2024

-- Flying Script for Roblox (Character Controlled)

-- Variables
local player = game.Players.LocalPlayer
local flying = false
local speed = 50 -- Flight speed
local liftSpeed = 20 -- Vertical speed (up/down)

-- Create a BodyGyro and BodyVelocity to control movement
local function startFlying(character)
if not character:FindFirstChild("Humanoid") then return end

local humanoid = character.Humanoid

-- Create a BodyGyro and BodyVelocity to control flight
local bodyGyro = Instance.new("BodyGyro")
bodyGyro.Parent = character.HumanoidRootPart
bodyGyro.MaxTorque = Vector3.new(4000, 4000, 4000)
bodyGyro.D = 20  -- Turn speed

local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Parent = character.HumanoidRootPart
bodyVelocity.MaxForce = Vector3.new(4000, 4000, 4000)
bodyVelocity.Velocity = Vector3.new(0, 0, 0)

-- Handle controls for flying
local userInputService = game:GetService("UserInputService")

-- Control variables
local direction = Vector3.new(0, 0, 0)  -- Movement direction
local isFlying = true  -- Flying status

-- Update loop for flight
local function fly()
    while isFlying and character:FindFirstChild("HumanoidRootPart") do
        -- Update velocity and gyro for flight
        bodyVelocity.Velocity = direction * speed
        bodyGyro.CFrame = character.HumanoidRootPart.CFrame * CFrame.Angles(0, math.rad(player.Character.HumanoidRootPart.Orientation.Y), 0)

        wait(0.01)
    end

    -- Clean up when flight ends
    bodyGyro:Destroy()
    bodyVelocity:Destroy()
end

-- Start flying
fly()

end

-- Function to handle player input (WASD for movement)
local function onKeyPress(input, gameProcessed)
if not flying or gameProcessed then return end

-- Check for WASD input to move in different directions
if input.KeyCode == Enum.KeyCode.W then
    direction = direction + player.Character.HumanoidRootPart.CFrame.LookVector
elseif input.KeyCode == Enum.KeyCode.S then
    direction = direction - player.Character.HumanoidRootPart.CFrame.LookVector
elseif input.KeyCode == Enum.KeyCode.A then
    direction = direction - player.Character.HumanoidRootPart.CFrame.RightVector
elseif input.KeyCode == Enum.KeyCode.D then
    direction = direction + player.Character.HumanoidRootPart.CFrame.RightVector
elseif input.KeyCode == Enum.KeyCode.Space then
    -- Move up
    direction = direction + Vector3.new(0, 1, 0) * liftSpeed
elseif input.KeyCode == Enum.KeyCode.LeftControl then
    -- Move down
    direction = directi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant