• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Realistic Jump algorithm

 
W Pearce
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm able to create a simple jump in a side scroller (rise and fall at the same rate), but I'm for some reason unable to get a nice "rise at a slower and slower rate, peak, fall at a faster and faster rate" smooth arc. Does anyone have any ideas that might point me in the right direction? So far I have this, which rises at a slower(ish) rate over time, peaks smoothly, but then falls at a pretty slow rate. When a jump is performed by pressing a key, yVel is set to -10 and increases until it reaches just under 10 which does cause the object to rise then fall, just not how I'm looking for.




EDIT: Jeez, I hate it when a solution is so simple it's the last thing you think of. I've got it working now, but if anyone wants to contribute your own ideas of one, feel free to go ahead.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i recall my physics correctly,

delta D = V(init)*T + 1/2 A * T^2

or change in distance = initial velocity time time plus 1/2 acceleration time time squared.

 
Mich Robinson
Ranch Hand
Posts: 260
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This might be a bit simple but I'm sure it would look fine:
 
Sean Panting
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well... i know nothing about physics, but wat i have come up with that will fit your needs perfectly is the set of code below:

basically, it calculates the new x coordinate by taking x and adding it to the x axis speed minus friction. It calculates the new y coordinate by adding the current y to gravity plus y axis speed plus equals to gravity minus friction. you shall get a nice upward spring that gradually will make the object follow a arc... an arc like a really ball or something like that would look. so its realistic. if you need each jump to be successively smaller, this doesnt account for that. it performs the same jump arc every time... so, for wat i think you need, this will work just fine. Also, dont set friction or grav to like 3... it needs to be like 0.25 or 1.11... try it, and, if it does what i think itll do, you know why not to do it. oh, the variables need to be doubles... and yspd MUST be limited to a value below 20... it would do the same thing as setting the gravity and\or the friction to a big number... . variables: Friction(fric), x axis speed(xspd), gravity(grav), y axis speed(yspd). oh, to make the object jump, you need to put in the keylistener this little piece of code: Y*=-1;
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic