我怎樣才能得到的東西從X去Xgoal速度在Y秒? 的goalVelocity
設置爲(100,100)和它接近它,但它需要的時間太長到那裏。加速到X速度在Y秒
我可以將frameDelta
乘以20或100之類的數字,但我想知道要乘以frameDelta
以在幾秒鐘內達到goalVelocity
。
速度,goalVelocity和起源都是Vec2f
和frameDelta是float
現在我有這樣的代碼:
velocity = approach(goalVelocity, velocity, frameDelta);
origin = origin + velocity * frameDelta;
的方法的代碼是:
inline float approach(float flGoal, float flCurrent, float dt)
{
float flDifference = flGoal - flCurrent;
if (flDifference > dt)
return flCurrent + dt;
if (flDifference < -dt)
return flCurrent - dt;
return flGoal;
}
inline Vec2f approach(Vec2f flGoal, Vec2f flCurrent, float dt)
{
return Vec2f(approach(flGoal.x, flCurrent.x, dt), approach(flGoal.y, flCurrent.y, dt));
}
你知道爲什麼你使用'inline'? – 2014-12-19 05:58:21
我得到這個代碼在網上,我假設它只是因爲它是如此簡單的功能。 – 2014-12-19 05:59:40
你說'在Y秒內加速到X速度'。我看到你將'X'傳遞給'approach'(以'flGoal'的形式),但我沒有看到你傳遞了'Y'。 – 2014-12-19 06:00:23