
Fun with variable jump heights. Is there any way to make the fall smoother?
Keep in mind how acceleration works. Gravity for example, accelerates at 9.81 m/s
2. That little two is really important though. Without the
2, it simply means that's how far you go per second. Once the
2 is added, though, it means that you take your current velocity (let's say 10 m/s) and add the value of acceleration to your velocity again, every second (resulting in 19.81 m/s after 1 second). Since gravity is constant, if you split a second in half and added the acceleration, you'd add half of the rate of acceleration (getting 14.905 m/s).
Now, if we apply that to the jump mechanics of a character, as well as Newton's law which states objects will continue to move in the direction they're currently moving unless acted upon by another force (in this case, gravity), we can reason that we need to do this (not specific 'cause I don't know what language/engine you're using):
- Get current time time minus our time variable (see next line) - not required for the first run through
- Get time (system time, time since level load - any realtime clock) and set it to a variable; we'll call it time
- Divide your gravity constant (i.e. -9.81) by the time difference, in seconds.
- Add this value to the current velocity.
- Loop.
This is all assuming your handling gravity manually.