隨着這些等式的跳轉大小隨着每秒更新量的下降而下降。用Delta值乘以重力和跳躍力下降的數量,以及每次迭代所增加的時間(增量值是自上次更新後傳遞的毫秒數),人們會認爲它可以正常工作。重力方程 - 速度方程|爲什麼它只適用於某些FPS?
//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值未正確應用,那麼應用它的正確方法是什麼?
我不明白你是怎麼做到的。垂直速度通常是初始垂直速度減重力* timeElapsed。那麼jumpSpeed如何在每個幀減少時間Elasped * delta? 你的方程式對我來說似乎非常錯誤。 –
是的,我本質上是問什麼是正確的方程式。 'fGravity'是否適用於你所描述的方程(把它放在重力的位置)還是有缺陷? – GlassZee