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

Is there / does anyone know of an equation to calculate a humanoid's jump height from jump power?

Asked by
Songist 49
6 years ago

Is there an equation for this?

Here's an example of what I mean: Lets say a humanoid should be able to get to an object past a 3 block high wall. It should reach just that height, but no further. One can get very close to this number by plugging in different tests for jump power. However, I was looking for an equation which would output a height for any inputted jump power.

Thanks!

0
2.5-2.6 jumppower would let you jump 1 stud above surface with no animation (froze my char animation). User#17685 0 — 6y
0
The issue is that I don't think its a linear model Songist 49 — 6y

1 answer

Log in to vote
1
Answered by
ozzyDrive 670 Moderation Voter
6 years ago
Edited 6 years ago

The JumpPower property defines the initial Y velocity of the character when the jump is activated. This then comes down to rather basic physics. I set up a little ugly experiment that can give quite accurate results.

01local player = game.Players.LocalPlayer
02local character = player.Character or player.CharacterAdded:Wait()
03local humanoid = character:WaitForChild("Humanoid")
04 
05humanoid.Jumping:Connect(function()
06    --  First calculate the time it takes to reach the peak of the jump (v = Vector3.new() so we can exclude it)
07    --  v = v0 + at
08    local v0 = Vector3.new(0, humanoid.JumpPower, 0)
09    local a = -workspace.Gravity
10    local t = (v0 / -a).Y
11 
12    --  Caclulate the final position
13    --  x = x0 + v0*t + (1/2)*a*t^2
14    a = Vector3.new(0, a, 0)
15    local x0 = character.PrimaryPart.Position
View all 29 lines...

Forgot to mention; the Jumping event for some reason fires twice and it first does the calculations with incorrect values. But this should point you to the right direction.

To calculate the required JumpPower to reach a certain height, you can first calculate the potential energy (mgh) which when the jump starts is turned into kinetic energy ((1/2)mv^2). From there you can solve for v, which is the required velocity. You can also use this to calculate the height if you know the JumpPower.

01local player = game.Players.LocalPlayer
02local character = player.Character or player.CharacterAdded:Wait()
03local humanoid = character:WaitForChild("Humanoid")
04 
05local part = workspace.Part
06 
07local g = workspace.Gravity
08local m = 0 do
09    for _, part in next, character:GetDescendants() do
10        if part:IsA("BasePart") then
11            m = m + part:GetMass()
12        end
13    end
14end
15 
View all 25 lines...
0
Wow, thanks so much. Looks intimidating hahaha but I'll look through it in a bit and see if I can figure it out. Thanks again! Songist 49 — 6y
1
Agh still having so much trouble. Rather than finding how high you end up from jumping, I'm trying to now find the required jump power(x) to reach a certain height(y). I'm trying to rearrange it but having issues when I do. Do you have any suggestions of things to read up to help me? Because what you showed was excellent but my inexperience is taking a toll on figuring out what everything means Songist 49 — 6y
0
I updated the answer. You couldn't do that with the first method I provided. ozzyDrive 670 — 6y
0
It seems to struggle with smaller parts and really tall parts it goes a little over. This might be because I'm dumb and didn't calculate the height correctly. I'll update the answer again if I got time to figure it out later. ozzyDrive 670 — 6y
View all comments (3 more)
0
It all worked!! thanks so much! Once the player's y position starts to reach the height of the part suddenly it messes up, setting jumppower to 1000, but this was an easy fix by making jumppower = 10 (or something around there) whenever the equation outputs jumppower over a certain amount. Songist 49 — 6y
0
If you're talking about how the JumpPower becomes 1000 when the character is higher than the target point, you can simply check if the height is less than 0 and do what you want. I updated the answer to calculate the height from the feet so it works fine for smaller parts now but still overshoots the really high ones. ozzyDrive 670 — 6y
0
Well I can't tell you how incredibly helpful this is, thanks again Songist 49 — 6y
Ad

Answer this question