AnswerBun.com

How to achieve variable jump height in an elegant and natural way

Game Development Asked by eguneys on July 31, 2020

I am making a platformer, with a methodical approach to player physics. This is how I do variable jump height:

if not btn(?) then
   g_fall *= 1.5
end

if (not is_grounded) then
   // fall gravity
   p.ay = g_fall
end

p is the player, p.ay is the acceleration.

g_fall is the constant falling gravity, which I apply to the player’s acceleration if it’s not on the ground. If the player isn’t pressing the jump button I increase g_fall so player falls down quicker thus achieving variable jump height.

This is somewhat ok, but I have a spring where player can jump and it bounces player to the air.

hit.y = ispring.y - 2
hit.dx *= 0.2
hit.dy=-v0_jump * 1.5

hit is the player, v0_jump is the constant initial velocity I give to the player to jump.

When the player presses jump while on the spring, it jumps higher because the fall gravity is lower. But I want spring to give you the same jump height whether you press jump or not.

Now I could put a flag for spring jump and an if condition to test for spring jumps and adjust the fall gravity, but I am looking for a more elegant solution.

So what are some professional techniques for variable jump height that can solve my problem out of the box.

Add your own answers!

Related Questions

How to move a character from 1 to 3 squares on a grid?

0  Asked on January 23, 2021 by shunkashuu

     

Unity 2017.3.of3 Raycast2D randomly misses objects

1  Asked on January 15, 2021 by hesitatetowonder

     

How to fix the vibration while colliding?

1  Asked on January 13, 2021

   

Render order in 3/4 view game

0  Asked on January 10, 2021 by chuan-li

 

How can I control ads frequency?

1  Asked on January 10, 2021 by ruslan-plastun

   

Attach movement to each list object

1  Asked on January 9, 2021 by mavish

     

How to make a map surface object

1  Asked on January 8, 2021 by anonymous-entity

     

Coding Spelunky Edge Roll Mechanic

0  Asked on January 5, 2021 by austin-weaver

     

Creating a lookup table of datamaps in Harlowe/Twine

0  Asked on January 4, 2021 by the_e

   

Unity 4 – Some Rigidbodies Won’t Fall Asleep

5  Asked on January 3, 2021 by ryan-berserkguard-nrby

       

Unity PackageCache keeps having errors

0  Asked on December 31, 2020 by christopher-perry

 

Phaser Tiled map importing

1  Asked on December 30, 2020 by kabuto178

     

Change the colour of all particles on screen

1  Asked on December 27, 2020 by super-potato

   

How can you make a jump to a point using the Character Controller?

0  Asked on December 25, 2020 by aimon-z

   

Trouble destroying an SDL2 texture from another class

1  Asked on December 21, 2020 by gamer1

 

How to hide objects behind an invisible plane?

1  Asked on December 18, 2020 by hatinacat2000

       

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir