2016-04-18 9 views
0

How to:スラストのクランプクランプ他の力を無限にすることができます。クランププレイヤーのスラストの影響

例:ロケットは回転方向に推力を持つことができます。爆発だけが最高速度を越えることができます。私はコード以上の理論を探しています。

ご協力いただければ幸いです。トップ速度はスラスト速度と摩擦によって決定される:

EDITを解決しました。

スラストは速度に積み重ねられますが、摩擦がスラスト速度よりも強ければ最高速度に達することができます。

vx = (vx + fx) *fr -- velocity = (velocity + force) *friction 
vy = (vy + fy) *fr 

速度が十分速い場合、摩擦による力の加算が差し引かれます。

fr = .9

fr = .6トップスピードを参照してくださいするのは難しい:トップスピード

+0

でそう

boostAccel = boostAccel - maxAccel; 

詳細にlove2dを知らない人々が簡単にあなたを助けることができるようになりますので、あなたのコードといくつかの詳細情報を提供してください。これがlove2d-フレームワークで可能ならば、単に自走運動のみに最大速度を適用する – Piglet

+1

オブジェクトの速度は、2つの独立した速度の和です:「自走運動」(ある一定の制限があります)と「その他要因 "(これは無制限です)。 –

+0

オブジェクト 'max = 50'、' if vel> 50'オブジェクト 'force'は' vel'にどのように影響しますか? 「vel」は「force」を吸収するでしょうか。 –

答えて

0

コントロール見やすい:左、右をして推力の最高速度は、摩擦で調整することができます

推力。

-- VARIABLES 
player = { 
    frc = .95, -- friction 
    acc = .05, -- acceleration 
    max = .5, -- acceleration max 
    deg = 0, -- rotation in degree 
    rad = 0 -- rotation in radian 
    -- rotation is CW and 0 points to the right 
} 

-- MAIN UPDATE 
function love.update() 
    control(player) 
    applyVelocity(player) 
end 

-- UPDATE 
function control(a) 
    if L then addRotation(a,-5) end 
    if R then addRotation(a, 5) end 
    if U then thrustOn(a) else thrustOff(a) end 
end 
function applyVelocity(a) 
    -- velocity + force 
    a.vx = (a.vx + a.fx) *a.fr 
    a.vy = (a.vy + a.fy) *a.fr 
    -- position + velocity 
    a.x = a.x + a.vx 
    a.y = a.y + a.vy 
end 

-- OTHER 
function thrustOn(a) 
    accelerate(a) 
    rotateDist(a) 
end 
function thrustOff(a) 
    a.f = 0 -- integer of force is used to convert to point (x,y) with (rad) 
    a.fx = 0 
    a.fy = 0 
end 
function addRotation(a,deg) 
    a.deg = a.deg + deg 
    a.rad = math.rad(a.deg) -- math.sin/cos functions use radian instead of degree 
end 
function accelerate(a) 
    a.f = a.f + a.acc 
    if a.f > a.max then a.f = a.max end 
end 
function rotateDist(a) 
    -- end point of force rotated from player 
    a.fx = a.f *math.sin(a.rad) 
    a.fy = a.f *math.cos(a.rad) 
end 
0

最大速度を設定するために、摩擦限られた加速度を用い正確

前の回答では摩擦が速度に制限を設定することができていることが正しいですが、答えは制限を設定に関していくつかの詳細を逃しました。

まずあなたがフレーム

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; 
} 
関連する問題