The jump size with these equations decreases as amount of updates per second goes down. With a delta value multiplying gravity force and amount that jumpspeed force decreases, as well as time elapsed being added by delta every iteration (the delta value is the amount of milliseconds passed since last update), one would think that it would work fine.
//d is delta
...
if(isFalling||isJumping){
elapsedTime +=d;
//the elapsed time is the total amount of time passed since one started jumping,
//so that's logical to add the amount of time since last update.
long tesquared = (long) Math.pow(elapsedTime, 2);
//amount of time elapsed squared.
jumpSpeed+=-0.0000005*elapsedTime*d;
//this is the amount that jumpspeed is taken down by every time.
if(jumpSpeed > 0){
isJumping = true;
} else {
isJumping = false;
}
double fGravity = 0.0000001*tesquared*d;
// this is the equation for gravity, the amount that the player goes down
yRend += jumpSpeed - fGravity;
//the amount it goes up, minus the amount it goes down.
xRend -= strafeSpeed;
oldyRend = yRend;
}
To start a jump, one adds jumpSpeed by whatever amount.
The problem is that when the amount of updates per second decreases, the jumps decrease in duration and magnitute. I'm fairly certain that the delta values here are fine, which means that the problem must be in the equations themselves.
I'm thinking that fGravity
is overrunning jumpSpeed
more quickly when the delta is larger.
So my question. If the problem really is in the equations themselves, what is the correct way to model the upward force of a player minus the downward gravity force other than
jumpSpeed+=-0.0000005*elapsedTime*d;
and
double fGravity = 0.0000001*tesquared*d;
?
If the problem is in the delta value not being applied correctly, then what would be the correct way to apply it?
Basically the equation of a jump are like that:
the gravity applies vertically and produce a constant force downward. So the vertical velocity is vy = vy0 - elapsedTime * g with g being the gravity constant and vy0 the initial velocity at the beginning of the jump.
You don't have to compute the elapsed time. Simply at every frame, you do this:
vy -= g * dt; // dt is the elapsed time since last frame
y += vy * dt;
x += vx * dt; // vx doesn't change in the jump