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.