Calculus? Need help solving for a time-dependent variable, given some other variables

In short, I am making a platform. I am not yet so old as to take Calculus yet, so I donโ€™t know derivatives or integrals, but I know them. The desired behavior is that my character automatically jumps when there is a block on either side of it that is higher than the one on which it stands; for example, stairs. Thus, the player can simply hold left / right to climb the stairs, instead of spamming the jump key.

The problem is how I implemented jumping; I decided to go mario style and let the player hold the jump longer to jump higher. To do this, I have a โ€œjumpโ€ variable that is added to player Yโ€™s speed. The jump variable increases to the set value when the โ€œjumpโ€ key is pressed, and decreases very quickly after pressing the โ€œjumpโ€ key, but decreases less quickly while you hold hold down the jump key, thereby providing continuous acceleration while you hold the jump. It also makes a pleasant, smooth leap, rather than a sharp sharp acceleration.

So, to take into account the variable height of the stairs, I want to be able to accurately calculate what value the variable โ€œjumpโ€ should get in order to accurately jump to the height of the stairs; preferably not more, not less, although a little more is permissible. Thus, the character can jump up steep or shallow flights of stairs without looking strange or slow.

There are essentially 5 variables in the game:

h -the height the character needs to jump to reach the stair top<br> j -the jump acceleration variable<br> v -the vertical velocity of the character<br> p -the vertical position of the character<br> d -initial vertical position of the player minus final position<br> Each timestep:<br> j -= 1.5; //the jump variable deceleration<br> v -= j; //the jump value influence on vertical speed<br> v *= 0.95; //friction on the vertical speed<br> v += 1; //gravity<br> p += v; //add the vertical speed to the vertical position<br> v-initial is known to be zero<br> v-final is known to be zero<br> p-initial is known<br> p-final is known<br> d is known to be p-initial minus p-final<br> j-final is known to be zero<br> j-initial is unknown<br> 

Given all these facts, how can I make an equation that will be solved with j?

tl; dr How is the calculus?

Many thanks to the one who has done this so far and decides to fail this problem.

Edit: Here is a graph that I made from an example in Excel. alt text

I need an equation that allows me to find the value for A given for B. Since the jump variable decreases with time, the position value is not just a simple parabola.

+7
source share
3 answers

There are two difficulties here. Firstly, you actually don't have j -= 1.5 , you have j = max(0, j - 1.5) . This leads to a calculation. In addition, your friction v *= 0.95 makes a direct solution difficult.

I would suggest using a lookup table for this. You can pre-program the desired a for each possible b , by trial and error (for example, a binary search on the values โ€‹โ€‹of a that give you the desired b ). Store the results in a table and just do a simple table search during the game.

+1
source

If I neglect the term friction and assume that j reaches zero before v reaches zero, I get after the calculation page that:

 b = 1/(8*(deceleration^2)*gravity)*j0^4 - 1/(6*deceleration^2)*j0^3 

the solution to this is quite long, but approximately equal (for 10 <b <400):

 j0 = (10*(deceleration^2)*gravity*b)^0.25 
+1
source

After extensively using Excel 2010 and the Go Go Go function, I was able to compile a table of values, and Excel gave me an approximate trend line and an equation for it, which I tuned until it worked out. The equation j = 3.35 * h ^ 0.966, where j is the initial force of the jump, h is the height required for the jump. Thank you for your help.

+1
source

All Articles