Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

flight help: how do i make it to where i move in any direction of my perspective during flight?

Asked by 1 year ago
Edited 1 year ago

heres my script:

local runService = game:GetService("RunService") local contextActionService = game:GetService("ContextActionService") local connection = nil local character = script.Parent local primaryPart = character.PrimaryPart local gravityVector = Vector3.new(0, game.Workspace.Gravity, 0) local yAxis = 0 local force = 400 local drag = 2

local vectorForce = script:WaitForChild("VectorForce") vectorForce.Attachment0 = primaryPart.RootRigAttachment

local alignOrientation = script:WaitForChild("AlignOrientation") alignOrientation.Attachment0 = primaryPart.RootRigAttachment

local function FlyAction(actionName, inputState, inputObject) if inputState ~= Enum.UserInputState.Begin then return Enum.ContextActionResult.Pass end if connection == nil then vectorForce.Enabled = true alignOrientation.Enabled = true character.Humanoid:ChangeState(Enum.HumanoidStateType.Physics) connection = runService.Heartbeat:Connect(function(deltaTime) vectorForce.Force = gravityVector * primaryPart.AssemblyMass local moveVector = Vector3.new(character.Humanoid.MoveDirection.X, yAxis, character.Humanoid.MoveDirection.Z) if moveVector.Magnitude > 0 then moveVector = moveVector.Unit vectorForce.Force += moveVector * force * primaryPart.AssemblyMass end if primaryPart.AssemblyLinearVelocity.Magnitude > 0 then local dragVector = -primaryPart.AssemblyLinearVelocity.Unit * primaryPart.AssemblyLinearVelocity.Magnitude ^ 1.2 vectorForce.Force += dragVector * drag * primaryPart.AssemblyMass end end) else vectorForce.Enabled = false alignOrientation.Enabled = false character.Humanoid:ChangeState(Enum.HumanoidStateType.Freefall) connection:Disconnect() connection = nil end return Enum.ContextActionResult.Pass end

local function UpAction(actionName, inputState, inputObject) if inputState == Enum.UserInputState.Begin then yAxis = 1 else yAxis = 0 end return Enum.ContextActionResult.Pass end

local function DownAction(actionName, inputState, inputObject) if inputState == Enum.UserInputState.Begin then yAxis = -1 else yAxis = 0 end return Enum.ContextActionResult.Pass end

contextActionService:BindAction("Fly", FlyAction, true, Enum.KeyCode.LeftShift) contextActionService:SetTitle("Fly", "Fly") contextActionService:SetPosition("Fly", UDim2.new(1, -150, 1, 08))

contextActionService:BindAction("Up", UpAction, true, Enum.KeyCode.Space) contextActionService:SetTitle("Up") contextActionService:SetPosition("Up", UDim2.new(1, -55, 1, -145))

contextActionService:BindAction("Down", DownAction, true, Enum.KeyCode.S) contextActionService:SetTitle("Down") contextActionService:SetPosition("Down", UDim2.new(1, -105, 1, -145))

~~~~~~~~~~~~~~~~~

0
Please remember to put it in lua text, there should be a button that is blue and it says lua then inside of the ~ that's where you put your script. I can't read this script currently but I can point you to tweening darkkitten12345 8 — 1y
0
body movers and camera.CFrame.LookVector Puppynniko 1059 — 1y

Answer this question