Not sure how to handle gliding with bodyforce

I like duplicating mechanics and cool scripted things from games I play but I haven’t really conquered the physical part of Roblox, I need help a script that accomplishes this:
https://gyazo.com/c0b8bf51798aa34c14fd842c71151729

The issue is I’m not quite sure if I’m using the correct BodyMover (I’m using bodyforce) and right now with the bodyforce I don’t know how to manage the force so that it always keeps the player floating but not flying

Here is the script I’ve written so far:

local uis = game:GetService("UserInputService")
local char = game.Players.LocalPlayer.Character

local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://4819428244"
local Anim = char.Humanoid:LoadAnimation(anim)

local mass = 0
    for i, v in pairs(char:GetChildren()) do
       if v:IsA("BasePart") then
        mass = mass + v:GetMass()
    end
end

local LastPress
uis.InputBegan:Connect(function(input, gpe)
	if not gpe and input.KeyCode == Enum.KeyCode.Space then
		local Time = tick() - (LastPress or 0)
		if (Time > 0.25) and char.Humanoid:GetState() == Enum.HumanoidStateType.Freefall then
    		Anim:Play()
	    	Anim.KeyframeReached:Wait()
		    Anim:AdjustSpeed(0)
		    local bv = Instance.new("BodyForce")
    		bv.Force = Vector3.new(0, (mass * workspace.Gravity) ,0)
	    	bv.Parent = char.Torso
	    else
		    LastPress = tick()
	    end
    end
end)

The part where I’m stuck is how I would change the upwards force in order to keep the player gliding against the constant force of gravity because (mass * workspace.Gravity) won’t always be enough to keep the player from falling quickly depending on how fast they are falling when the bodyforce is added

And I can’t keep it permanently above (mass * workspace.Gravity) because then if the player activates this on the ground, they’ll just start floating, so the major question is would I have to calculate how fast the character is falling and counteract that fall with some more force to always have them falling at a certain rate, or is there another way around this?

1 Like

Use their angle of descent to change their speed (The direction of their velocity). The closer it is to pointing toward the floor, increase their speed over time. The higher up it points, reduce their speed over time. Simple way of checking this is something like:

--moveDir.Y to get how far up the Y axis their direction goes, from -1 to 1
speed = clamp(speed - changeInTime * 20 * (moveDir.Y * 0.5 + 0.2), 0, 50)
3 Likes