Hi,
I’m trying to make a sort of gliding system in my game, where if you hold the jump button in the air, you’ll automatically get propelled forward, but still descend slightly, with left and right movements still allowing you to turn left and right.
I’m not exactly sure how to accomplish this.
I considered using BodyVelocity, but that only does world space. I could convert it to local space, but then I fear I’d have to convert it in a fast, constantly-updating loop, since I’d allow left-and-right turning.
I’ve also tried VectorForce, but it didn’t seem to do anything to the player. Here’s my script for that:
local player = game.Players.LocalPlayer
player.CharacterAdded:wait()
local character = player.Character
local mouse = player:GetMouse()
local humanoid = character:WaitForChild("Humanoid")
local jumpvar = 0
local deb = 0
if game:GetService("UserInputService").TouchEnabled == true then
jumpb = game.Players.LocalPlayer.PlayerGui.TouchGui.TouchControlFrame.JumpButton
end
function jumpRequest()
if deb == 0 then
deb = 1
jumpvar = 1
end
end
function Glide()
print("Gliding! maybe?")
local vectorforce = Instance.new("VectorForce")
vectorforce.Enabled = false
vectorforce.Parent = character.HumanoidRootPart
vectorforce.Force = Vector3.new(0,0,500)
vectorforce.ApplyAtCenterOfMass = true
local attachment = Instance.new("Attachment")
attachment.Parent = character.HumanoidRootPart
attachment.Position = Vector3.new(0,0,-0.5)
vectorforce.Attachment0 = attachment
vectorforce.Enabled = true
end
game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.Space and jumpvar == 1 then
Glide()
end
end
if input.UserInputType == Enum.UserInputType.Gamepad1 or input.UserInputType == Enum.UserInputType.Gamepad2 then
if input.KeyCode == Enum.KeyCode.ButtonA and jumpvar == 1 then
Glide()
end
end
end)
if game:GetService("UserInputService").TouchEnabled == true then
jumpb.InputBegan:connect(function(inputObject)
if jumpvar == 1 then
Glide()
end
end)
end
game:GetService("UserInputService").JumpRequest:Connect(jumpRequest)
The script isn’t done, but I can get it to print, yet nothing happens afterwards. What might be a good way to accomplish this?