Featured post
math - Calculus? Need help solving for a time-dependent variable given some other variables -
long story short, i'm making platform game. i'm not old enough have taken calculus yet, know not of derivatives or integrals, know of them. desired behavior character automagically jump when there block either side of him above 1 he's standing on; instance, stairs. way player can hold left / right climb stairs, instead of having spam jump key too.
the issue way i've implemented jumping; i've decided go mario-style, , allow player hold 'jump' longer jump higher. so, have 'jump' variable added player's y velocity. jump variable increases set value when 'jump' key pressed, , decreases once 'jump' key released, decreases less long hold 'jump' key down, providing continuous acceleration long hold 'jump.' makes nice, flowing jump, rather visually jarring, abrupt acceleration.
so, in order account variable stair height, want able calculate value 'jump' variable should in order jump height of stair; preferably no more, no less, though more permissible. way character can jump steep or shallow flights of stairs without looking weird or being slow.
there 5 variables in play:
h -the height character needs jump reach stair top<br> j -the jump acceleration variable<br> v -the vertical velocity of character<br> p -the vertical position of character<br> d -initial vertical position of player minus final position<br> each timestep:<br> j -= 1.5; //the jump variable's deceleration<br> v -= j; //the jump value's influence on vertical speed<br> v *= 0.95; //friction on vertical speed<br> v += 1; //gravity<br> p += v; //add vertical speed vertical position<br> v-initial known zero<br> v-final known zero<br> p-initial known<br> p-final known<br> d known p-initial minus p-final<br> j-final known zero<br> j-initial unknown<br>
given of these facts, how can make equation solve j?
tl;dr how calculus?
much who's made far , decides plow through problem.
edit: here's graph made of example in excel.
i want equation let me find value given desired value b. since jump variable decreases on time, position value isn't simple parabola.
there 2 difficulties in play here. first don't have j -= 1.5
, have j = max(0, j - 1.5)
. throws of wrench calculations. also, friction term v *= 0.95
makes direct solution difficult.
i suggest using lookup table this. can precalculate desired a
each possible b
, trial , error (e.g. binary search on values of a
give required b
). store results in table , simple table lookup during game.
- Get link
- X
- Other Apps
Comments
Post a Comment