wood burning stoves
The moose likes Game Development and the fly likes Realistic Jump algorithm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Game Development
Bookmark "Realistic Jump algorithm" Watch "Realistic Jump algorithm" New topic

Realistic Jump algorithm

W Pearce
Ranch Hand

Joined: Jan 06, 2009
Posts: 32
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

Joined: Oct 02, 2003
Posts: 11955

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.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Mich Robinson
Ranch Hand

Joined: Jun 28, 2009
Posts: 260
This might be a bit simple but I'm sure it would look fine:

Arcade : Alien Swarm
Board : Chess - Checkers - Connect 4 - Othello
Sean Panting

Joined: Oct 13, 2010
Posts: 3
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;
I agree. Here's the link: http://aspose.com/file-tools
subject: Realistic Jump algorithm
It's not a secret anymore!