Answered by
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.
01 | local player = game.Players.LocalPlayer |
02 | local character = player.Character or player.CharacterAdded:Wait() |
03 | local humanoid = character:WaitForChild( "Humanoid" ) |
05 | humanoid.Jumping:Connect( function () |
08 | local v 0 = Vector 3. new( 0 , humanoid.JumpPower, 0 ) |
09 | local a = -workspace.Gravity |
14 | a = Vector 3. new( 0 , a, 0 ) |
15 | local x 0 = character.PrimaryPart.Position |
16 | local v 0 = character.PrimaryPart.Velocity |
17 | local x = x 0 + v 0 *t + ( 1 / 2 )*a*t^ 2 |
22 | local startPos = character.PrimaryPart.Position |
23 | local connection = game:GetService( "RunService" ).Heartbeat:Connect( function () |
24 | tab [ #tab + 1 ] = character.PrimaryPart.Position.Y - startPos.Y |
27 | connection:Disconnect() |
28 | print ( "PEAKED AT" , startPos + Vector 3. new( 0 , math.max( unpack (tab)), 0 )) |
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.
01 | local player = game.Players.LocalPlayer |
02 | local character = player.Character or player.CharacterAdded:Wait() |
03 | local humanoid = character:WaitForChild( "Humanoid" ) |
05 | local part = workspace.Part |
07 | local g = workspace.Gravity |
09 | for _, part in next , character:GetDescendants() do |
10 | if part:IsA( "BasePart" ) then |
11 | m = m + part:GetMass() |
16 | humanoid.Jumping:Connect( function () |
20 | local footPos = character.PrimaryPart.Position - Vector 3. new( 0 , 2 , 0 ) |
22 | local h = (part.Position + Vector 3. new( 0 , part.Size.Y/ 2 , 0 ) - footPos).Y |
23 | local v = math.sqrt( 2 ) * (math.sqrt(m * m*g*h) / m) |
24 | humanoid.JumpPower = v |