Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(3 edits) (+1)

If You Donwload the File

1. Found that you press jump on air, you will boost Down.

2. SuperJump when hit ground.


You can change Code like below, it may fix the problem.

```
+    private Vector2 groundGravity;  
     void Awake() {  
       ...             
+      groundGravity = new Vector2(0, (-2 * jumpHeight) / (timeToJumpApex * timeToJumpApex));
       ...
     }           
     private void setPhysics() { 
-      Vector2 newGravity = new Vector2(0, (-2 * jumpHeight) / (timeToJumpApex * timeToJumpApex)); 
-      body.gravityScale = (newGravity.y / Physics2D.gravity.y) * gravMultiplier;  
+      // ( Ground Gravity ) * ( Gravity Multiplier).  
+      body.gravityScale = (groundGravity.y / Physics2D.gravity.y) * gravMultiplier;
     }            
     private void FixedUpdate() { 
        ...
-      if (desiredJump)
+      if (desiredJump && onGround)  
        ...
} 
 
     private void DoAJump()  {
      ...  
-      jumpSpeed = Mathf.Sqrt(-2f * Physics2D.gravity.y * body.gravityScale * jumpHeight);  
+      jumpSpeed = Mathf.Sqrt(-2f * Physics2D.gravity.y * (groundGravity.y / Physics2D.gravity.y) * jumpHeight);
      ...  
}
```
(1 edit) (+1)

1. JumpSpeed should calulate base on ground gravityScale

, not current gravityScale, that why Super Jump happen.


2. boost Down is because of when jumpbuffer save the desiredJump, 

DoAJump() will not change the velocity,  but calculateGravity will not trigger, that is reason.


note:

I cache the groundGravity so if you want runtime change jump height.

Must Recalulate groundGravity.


and If anything wroung please tall me.