Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

tyomiboy

5
Posts
2
Following
A member registered Jun 26, 2022 · View creator page →

Creator of

Recent community posts

I also hit the issue with the "super" jump, when jumping just before landing.


I think it's happening at the moment when the player is just above the ground -> ground check with raycasts says that the player is grounded, but the player's gravity scale is still upscaled for falling.


At that moment, the jump velocity is calculated based on "falling" gravity scale, but at the next frame the gravity scale is downscaled, because player is moving up now. This means that the players velocity is too high, for the new gravity scale, and the player will jump too high.


The fast and easy fix was to update gravityMultiplier and gravityScale at the top of the FixedUpdate, before DoJump() function is called, so it can operate on correct/newest values. Maybe there's a better solution, but this will work for now.


Idk if this is still relevant to you, just posting in case if anyone else stumbles across this issue. 

From what I understand, the jump height and duration are set as constants, and the speed at which player is jumping and falling is being calculated based on those constants.

Great tutorial! SUPER informative and fun at the same time. Thank you for making and sharing this with us <3


I wanted to understand the math responsible for jumping, so just in case if anyone else is interested, here's what I got so far.

I'm excluding gravity scaling for the sake of simplicity and clarity, but it can be easily plugged into the formulas.


New Gravity Calculation:

Vector2 newGravity = new Vector2(0, (-2 * jumpHeight) / (timeToJumpApex * timeToJumpApex)); 
body.gravityScale = (newGravity.y / Physics2D.gravity.y) * gravMultiplier;

using the formula:      

distanceTravelled = 0.5 * gravity * time^2



Jump Speed calculation, based on current gravity:

jumpSpeed = Mathf.Sqrt(-2f * Physics2D.gravity.y * body.gravityScale * jumpHeight);

using formulas:

currentVelocity = gravity * time

distanceTravelled = 0.5 * gravity * time^2


In the code, the multiplier inside sqrt is -2,  because the in unity gravity has a direction (down, duh...), thus it's negative. Whereas this formula considers g as magnitude, without direction, making it  positive. To account for this, we multiply g by -1, and get  -2 * g * d. (I hope this gibberish makes sense)

Great idea, but I would love to have a better understanding of where the ball is.

Maybe having a map of the area, or having the victim look at the direction of the ball when using ball power would be great.

thank you!!