最大速度を設定するために、摩擦限られた加速度を用い正確
前の回答では摩擦が速度に制限を設定することができていることが正しいですが、答えは制限を設定に関していくつかの詳細を逃しました。
まずあなたがフレーム
maxVelocity = 100; // set the maximum speed
あたりのピクセル数で特定の最大速度をしたいそして、あなたは、フレームあたりのピクセル数で特定の最大加速度を持って
vel = 0; //in pixels per frame. Start at 0 (or wherever you want)
そして、あなたの速度変数
maxAccel = 1; // The max acceleration will occur when accelerating from 0
速度が100に達したときに摩擦が加速を停止するために必要な取得するために私たちは、あなたがfriction
は後に速度を下げる必要があることを知っているあなたは、式
vel = vel + maxAccel; // accelerate
vel = vel * friction; // add friction
を使用することになり、未知の摩擦
friction = null; // what we need to find out
呼び出します。アクセラレーションのため、maxVelocity
を超えません。だから我々は今、あなたが値を持っている今だけ
friction = maxVelocity/(maxVelocity + maxAccel);
を取得するために、未知のfriction
を解くために式を並べ替えるmaxVelocity + maxAccel
に適用した場合には、maxVelocity
maxVelocity = (maxVelocity + maxAccel) * friction;
に等しいことをfriction
の値を必要としますfriction
あなたの速度がmaxVelocity
を超えないようにします。
少し長く伸ばすには、短時間の余分なベロシティを与えるブーストを追加することができますが、そのブーストベロシティが限界を超えないようにすることができます。 friction
を新しいmaxVelocity
に再計算することはできますが、速度カーブの上端の加速度が低いため、蹴っていない可能性があります。
もう1つの方法は、同じ摩擦を維持しながら追加の加速を計算することです。私たちは新しいヴァースが必要です。
ので、上記と同じロジックを使用しますが、新たな最大速度の面で摩擦ソリューションを再配置し、我々は
boostAccel = ((maxBoostVelocity/friction)- maxBoostVelocity);
を取得し、既知の摩擦で、私はブーストのためにのみ、追加のアクセラレーションを使用したいと
maxBoostVelocity = 120; // max boost velocity
boostAccel = null; // this will have to be calculated using the friction we have
私は既存の加速値に触れる必要はありません。だから私はちょうど私が欲しいものを得るために計算されたブーストから元の加速を引く。いくつかのコード
// the known limits
vel = 0; //in pixels per frame. Start at 0 (or wherever you want)
maxVelocity = 100; // set the maximum speed
maxAccel = 1; // The max acceleration will occur when accelerating from 0
maxBoostVelocity = 120; // max boost velocity
accelerate = false; // flag to indicate that we want to accelerate
boost = false; // flag to indicate we want to boost
// the unknown friction and boost accel
boostAccel = null; // this will have to be calculated using the friction we
friction = null; // what we need to find out
function applyAcceleration()
if(boost){ // is boosr flag true then add boost
vel += boostAccel ; // boost
}
if(accelerate || boost){ // is accelerate or boost flag true
vel += maxAccel; // accelerate
}
// always apply the friction after the accelerations
vel *= friction; // apply friction
}
// in the init function calculate the friction and boost acceleration
function init(){
friction = maxVelocity/(maxVelocity + maxAccel);
boostAccel = ((maxBoostVelocity/friction)- maxBoostVelocity) - maxAccel;
}
でそう
詳細にlove2dを知らない人々が簡単にあなたを助けることができるようになりますので、あなたのコードといくつかの詳細情報を提供してください。これがlove2d-フレームワークで可能ならば、単に自走運動のみに最大速度を適用する – Piglet
オブジェクトの速度は、2つの独立した速度の和です:「自走運動」(ある一定の制限があります)と「その他要因 "(これは無制限です)。 –
オブジェクト 'max = 50'、' if vel> 50'オブジェクト 'force'は' vel'にどのように影響しますか? 「vel」は「force」を吸収するでしょうか。 –