这些方程的跳跃大小随着每秒更新量的下降而减小。使用 delta 值乘以重力和 jumpspeed 力减小的量,以及每次迭代都通过 delta 增加经过的时间(delta 值是自上次更新以来经过的毫秒数),人们会认为它可以正常工作。
//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;
}
要开始跳跃,可以将 jumpSpeed 增加任意数量。
问题在于,当每秒更新量减少时,跳跃的持续时间和幅度都会减少。我相当肯定这里的 delta 值很好,这意味着问题必须出在方程本身。
我认为当增量较大时,它fGravity
会jumpSpeed
更快地超出。
所以我的问题。如果问题真的出在方程本身,那么模拟玩家向上的力减去向下的重力的正确方法是什么?
jumpSpeed+=-0.0000005*elapsedTime*d;
和
double fGravity = 0.0000001*tesquared*d;
?
如果问题在于未正确应用 delta 值,那么应用它的正确方法是什么?