Trouble with creating flight system

Hi everyone, I’ve been working on creating a flight system for a game I’m working on, but I’m not too well-versed in using things like velocities and forces which has really put a halt to it. I made it so that whenever the player double taps space they enter into it and then after pressing it again while in the air they stop. Here’s my script down here so far.

   local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

local Animator = Humanoid:FindFirstChildOfClass("Animator")

local LastClicked = tick()
local InFlight = false
local TimesClicked = 0
local Cooldown = false

UserInputService.InputBegan:Connect(function(input, gpe)
	if gpe then return end
	if Cooldown then return end
	if input.KeyCode == Enum.KeyCode.Space then
		if TimesClicked == 0 then
			TimesClicked += 1
		else
			if tick() - LastClicked < 0.7 then
				TimesClicked += 1
				if TimesClicked > 2 then
					TimesClicked = 2 
				end
			end
		end
		if TimesClicked == 2 then
			if not InFlight then
				TimesClicked = 0
				InFlight = true
				Cooldown = true
				Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
				print("ACTIVATED")
				task.delay(0.3, function()
					local FlightVelocity = Instance.new("BodyVelocity", HumanoidRootPart)
					FlightVelocity.Velocity = Vector3.new(0, 0, 0)
				end)
				task.delay(1, function()
					Cooldown = false
				end)
			elseif InFlight then
				TimesClicked = 0
				InFlight = false
				Cooldown = true
				HumanoidRootPart.BodyVelocity:Destroy()
				task.delay(1, function()
					Cooldown = false
				end)
			end
		end
		LastClicked = tick()
	end
end)

I used a body velocity that didn’t point into any direction to start the hover, but other than that I haven’t really done anything to it. If anyone can help me from here on that’d be awesome. I want it so that it moves the body depending on which wasd keys they are holding down to move, just like regular ground movement. Also wherever the camera points they move in that direction, up or down.

1 Like

Just a heads up, BodyVelocity is deprecated and it’s recommended that you use LinearVelocity. If you want the player to move in the direction of the camera, you could use the LookVector for forward, -LookVector for backward, RightVector and -RightVector for side to side. Humanoid.PlatformStand is optional, but it’s good for that flying spectator vibe.

workspace.CurrentCamera.CFrame.LookVector

How would I make it so that it also changes depending on which WASD keys the player is pressing? I want it so that the camera controls if the player is moving upwards or downwards, then WASD to control directions. Thanks for letting me know about lookvectors though, I’ll look into them it will probably help too.

I presume you want the WASD to be relative of the camera as well? Not sure if you want that to be static or for that to follow the camera such that forward will be the direction the camera is facing.