Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I increase Jump Height while maintaining the same falling speed?

Asked by 9 years ago
VAR_GRAV = 2

local bf = Instance.new("BodyForce",char.Torso)
bf.force = Vector3.new(0,196.2 * VAR_GRAV,0) * bf.Parent:GetMass()

Yeah, this is all fine and dandy. The code makes the character jump higher, but at the same time, it makes him fall slower, and that's a no-no. All this does is reduce gravity on the player, and that's not what I want.

What I want is a code that will allow the character to jump high while still maintaining the normal speed of falling down. Thanks in advance :>

--EDIT--

Work's like a charm :) Here's the script for those interested. It is local script that is located within the character's Torso.

wait()
local char = script.Parent.Parent
if (char:findFirstChild("Humanoid") == nil) then return print("Not a human") end

----------
-- DATA --
----------

VAR_GRAV = 2.5

---------------
-- FUNCTIONS --
---------------

function getCharMass()
    local sum = 0
    for _,v in pairs(char:GetChildren()) do
        if v:IsA("Part") then
            sum = sum + v:GetMass()
        end
    end
    return sum
end

function createGrav()
    if (char.Torso:findFirstChild("GravityForce") ~= nil) then char.Torso.GravityForce:Destroy() end
    local bf = Instance.new("BodyForce",char.Torso)
    bf.Name = "GravityForce"
    bf.force = Vector3.new(0,196.2 * VAR_GRAV,0) * getCharMass()
    wait()
    bf:Destroy()
end

char.Humanoid.Jumping:connect(function(jump)
    if (jump) then
        createGrav()
    end
end)

1 answer

Log in to vote
4
Answered by 9 years ago

Roblox's acceleration due to gravity is 196.2 studs/second^2 whereas in the real world it's 9.81 meters/second^2

What this means is that every second, the y component of the velocity of a falling object increases by 196.2.

When you have a BodyForce inserted into the player, that bodyforce counters the force of gravity in the game, and reduces the acceleration due to gravity, which means that the player will fall slower.

The most effective solution to your problem that I know of is to have the script create a bodyforce in the player when the player jumps, and then have the script delete that bodyforce within half a second or less. That way, the force will only act on the player during the player's ascension, but the player will still descend at the normal roblox gravity acceleration.

But because the force is only there for a very short amount of time, you will need to increase the force acting on the player.

Some useful formulas:

^V - Change in velocity

F - Force

t - time

m - mass of object

a - acceleration

^V = F*t / m

a = F / m

F = m * a

Hope this helped!

Ad

Answer this question