Tip of the Week #9: Gravity and Jumping? No Problem!

Posted By: Superku

Tip of the Week #9: Gravity and Jumping? No Problem! - 06/30/13 21:11

A new Tip of the Week, learn how to create a robust gravity and jumping code (that works on low framerates, too)!



http://opserver.de/pwik7/index.php?title=Tip_of_the_Week
Posted By: alibaba

Re: Tip of the Week #9: Gravity and Jumping? No Problem! - 06/30/13 21:49

Wow! You are just awesome!!

This was one of the most annoying problems which occured during developement, but now itīs solved thanks to you laugh
Posted By: Kartoffel

Re: Tip of the Week #9: Gravity and Jumping? No Problem! - 06/30/13 22:07

Whenever I tried to create a player script I had huge problems with gravity and jumping grin
... so this is just perfect.

Thaks a lot laugh
Posted By: Superku

Re: Tip of the Week #9: Gravity and Jumping? No Problem! - 07/01/13 11:42

Thanks guys, I'm glad you find it useful!
Posted By: Firoball

Re: Tip of the Week #9: Gravity and Jumping? No Problem! - 07/02/13 20:15

using c_trace after c_move is a very good hint.

However I had huge problems getting a proper time corrected jump.
What I did in the end was introducind a jump timer. This timer increments to a certain value and during that time I apply a z-force (which has to be big enough to overcome gravity). Then I used vec_acclerate to get a speed out of my force vector and handed it over to c_move.

Not sure if this is the correct solution, but it seemed to eliminate all my framerate dependencies.
Posted By: Ruben

Re: Tip of the Week #9: Gravity and Jumping? No Problem! - 09/06/13 10:17

Superku: When I click on either of your three links, I am forwarded to some website called "Compact Dictionary of the Infinite", at this link:

*any website*

I don't think this is the website you intended your links to be connected to, is it?
Posted By: MasterQ32

Re: Tip of the Week #9: Gravity and Jumping? No Problem! - 09/06/13 14:38

it is now nwiki5 instead of mwiki4
Posted By: rayp

Re: Tip of the Week #9: Gravity and Jumping? No Problem! - 09/06/13 14:50

@Ruben
Added a working link in SuperKu's first post above.
Posted By: CanadianDavid

Re: Tip of the Week #9: Gravity and Jumping? No Problem! - 12/19/13 07:05

Works nicely except do you know why the player can go through ceilings and off the map when walking up slopes or stairs? See the attached map and walk to the end of the map. It is possible to jump off the map as well as jump onto the platform. I presume it is due to manually adjusting the my.z, circumventing collision detection.

Attached File
bug.zip  (34 downloads)
Posted By: Superku

Re: Tip of the Week #9: Gravity and Jumping? No Problem! - 12/19/13 07:52

Thanks for noticing that, I've updated the code (wiki download link) and improved it in 1-2 other situations.
Posted By: CanadianDavid

Re: Tip of the Week #9: Gravity and Jumping? No Problem! - 12/19/13 10:58

Thanks! The code works even better! One more thing I noticed is that there can be some circumstances where downward speed is applied until the maximum downward speed is reached (-90 in the example code) which would be undesirable. In the attached image I have created another dummy entity that does nothing but act like an obstacle. The player can jump above it and hang off the other entity, accumulating downward speed that is not applied until the player moves off.


Attached File
shot_0.jpg  (457 downloads)
Attached File
gravity.zip  (56 downloads)
Posted By: Superku

Re: Tip of the Week #9: Gravity and Jumping? No Problem! - 12/19/13 11:15

You will encounter at least 100 other problems with this or with any other movement code/ basis this short. Movement codes are not simply using a single or two provided engine functions but oftentimes consist of tens of thousands lines of code.
Posted By: CanadianDavid

Re: Tip of the Week #9: Gravity and Jumping? No Problem! - 12/19/13 11:27

It's really not a problem at all; I'm just posting my results with this code. Thank you for sharing!
Posted By: Superku

Re: Tip of the Week #9: Gravity and Jumping? No Problem! - 12/19/13 13:22

Feel free to add your discoveries and fixes to the wiki article (I think adding it at the bottom of the article would be best)!
Posted By: 3run

Re: Tip of the Week #9: Gravity and Jumping? No Problem! - 09/25/19 08:16

Since there are no working links (at least I couldn't find any), here is the gravity code (the latest one I have) hosted on my webpage:
Download link

PS: thank you jcl for not even trying to run back acknex wiki.
© 2020 lite-C Forums