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!
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)