Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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!

2 comments

0

2.5-2.6 jumppower would let you jump 1 stud above surface with no animation (froze my char animation).

0

The issue is that I don't think its a linear model

1 answer

✓ Accepted answer

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.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

humanoid.Jumping:Connect(function()
	--	First calculate the time it takes to reach the peak of the jump (v = Vector3.new() so we can exclude it)
	--	v = v0 + at
	local v0 = Vector3.new(0, humanoid.JumpPower, 0)
	local a = -workspace.Gravity
	local t = (v0 / -a).Y

	--	Caclulate the final position
	--	x = x0 + v0*t + (1/2)*a*t^2
	a = Vector3.new(0, a, 0)
	local x0 = character.PrimaryPart.Position
	local v0 = character.PrimaryPart.Velocity
	local x = x0 + v0*t + (1/2)*a*t^2
	print("EXPECTED", x)


	local tab = {}
	local startPos = character.PrimaryPart.Position
	local connection = game:GetService("RunService").Heartbeat:Connect(function()
		tab[#tab + 1] = character.PrimaryPart.Position.Y - startPos.Y
	end)
	wait(t*2)
	connection:Disconnect()
	print("PEAKED AT", startPos + Vector3.new(0, math.max(unpack(tab)), 0))
end)

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.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local part = workspace.Part

local g = workspace.Gravity
local m = 0 do
	for _, part in next, character:GetDescendants() do
		if part:IsA("BasePart") then
			m = m + part:GetMass()
		end
	end
end

humanoid.Jumping:Connect(function()
	--	potential energy = kinetic energy
	--	mgh = (1/2)*m*v^2
	--	solve for v
	local footPos = character.PrimaryPart.Position - Vector3.new(0, 2, 0)
	--	 Keep in mind this example only works for parts that are standing straight. You can use pythagorean to find the height of tilted parts.
	local h = (part.Position + Vector3.new(0, part.Size.Y/2, 0) - footPos).Y
	local v = math.sqrt(2) * (math.sqrt(m * m*g*h) / m)
	humanoid.JumpPower = v
end)

7 comments

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!

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

0

I updated the answer. You couldn't do that with the first method I provided.

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.

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.

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.

0

Well I can't tell you how incredibly helpful this is, thanks again

This discussion is preserved as it was. New answers, comments, and votes are closed.