I have this piece of code here that increases and decreases the gliding speed of the player when they’re flying based on how much they’re going up and down. The problem with this is, if you glide upwards at the right angle, the player can just keep gliding upwards for as long as they want; that doesn’t happen, realistically, with a glider.
local perDown = direction.Unit.Y
velocity.Force += direction * 100 * (1 - perDown) * HRP.AssemblyMass
What I’m aiming for is allowing players to speed up as they dive down, but then slow back down once they go against gravity, like if they go up or are no longer diving down.
For example, if a player dives down and then quickly glides up, they’ll retain that speed going up but they’ll slow down until they can no longer go upwards (cuz gravity big and speed too small), so they’re forced to glide back down. This mechanic can be seen in Bird Simulator - Roblox and Glider Simulator [WORLD 2] - Roblox
The snippet you included seems to speed up players based on angle, but with no possibility of slowing them down, unless I’m missing something.
Each time the code runs, it adds an amount of force that scales with the direction the player points, but the math there means that force will never be negative. Is there drag or something not included here that fixes that, or am I misunderstanding the code?
oh there’s drag. The only issue lies in the code I provided, and you’re right. It speeds up players based on angle. After trial and error, I know that the speed doesn’t need to be negative; it only needs to be less than the force of gravity so that stops going up. At least, that’s my understanding of it.
Here’s the drag tho
if HRP.AssemblyLinearVelocity.Magnitude > 0 then
local dragVector = -HRP.AssemblyLinearVelocity.Unit * HRP.AssemblyLinearVelocity.Magnitude ^ DRAG_POWER
velocity.Force += dragVector * DRAG_COEFFICIENT * HRP.AssemblyMass
end
when the player is pointing up at a shallow angle, which lets them gain speed while gliding up. Can you correct it by changing the (1-perDown) line to say, (0.5-perDown)? Or if that’s too drastic, maybe a number in between until it feels good?
local GRAVITY = Vector3.new(0, game.Workspace.Gravity, 0)
local function onGlide()
velocity.Force = (GRAVITY/1.05 * HRP.AssemblyMass)
if humanoid_direction.Magnitude > 0 and direction.Magnitude > 0 then
local perDown = direction.Unit.Y
velocity.Force += direction * 100 * (1 - perDown) * HRP.AssemblyMass
end
if HRP.AssemblyLinearVelocity.Magnitude > 0 then
local dragVector = -HRP.AssemblyLinearVelocity.Unit * HRP.AssemblyLinearVelocity.Magnitude ^ DRAG_POWER
velocity.Force += dragVector * DRAG_COEFFICIENT * HRP.AssemblyMass
end
end
And the problem would occur when
velocity.Force.Y > (GRAVITY * HRP.AssemblyMass).Y
--velocity includes all the 3 values u see for velocity in the onGlide function added up
ur solutions was one of the things I tried. It doesn’t work. I put .75 for example, I can still find the angle to go up forever. If I do .5 for example, I also won’t be able to glide the way I want like in the game I linked. It doesn’t retain momentum if I were to dive down, but then glide back up, and then do it again