This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java and have Dr. Raoul-Gabriel Urma & Richard Warburton on-line!
See this thread for details.
Win a copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Realistic Jump algorithm

 
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.
 
lowercase baba
Posts: 12797
51
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.

 
Ranch Hand
Posts: 275
2
  • 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:
 
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;
 
We've gotta get close enough to that helmet to pull the choke on it's engine and flood his mind! Or, we could just read this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!