私は、衝突の際に円形オブジェクトに作用する力を計算しようとしています。残念なことに、私のメカニックはやや錆びているので少し問題があります。ゲームでの車両の2D合力の計算
は私がメンバー
vector position // (x,y)
vector velocity // (x,y)
vector forward // (x,y)
float radius // radius of the agent (all circles)
float mass
でエージェントクラスを持っているので、我々はA、Bがある場合:エージェント、および次回に速度が位置を変更しようとしているステップを。衝突が発生する場合、私はオブジェクトに作用する力を作り出したいと思います。
私はLine1 =(B.position-A.position)が合力の角度を計算するのに必要だと知っていますが、それをどのように計算するかは、私が車両の現在の速度と衝突の角度。
逆正接(L1.y、L1.x)が力のためにAM角で(方向を決定することができる) 罪/ COSコンポーネントの高さ/幅また
あるIは回転軸Iを計算するために知っています(T)* vel.y + sin(T)* vel.x
これは、次のように使用する必要があります。x = cos(T)* vel.x + sin(T)* vel.y 私の脳はもう対処できません。どんな助けもありがとうございます。
私が言うように、目的は基本的な物理を既に考慮しているので、オブジェクトに適用されるベクトル力を計算することです。
を追加しました、私はそれで行くことを始めていた場所を示すために少しpsudocode ..ここ
A,B:Agent
Agent {
vector position, velocity, front;
float radius,mass;
}
vector dist = B.position - A.position;
float distMag = dist.magnitude();
if (distMag < A.radius + B.radius) { // collision
float theta = arctan(dist.y,dist.x);
flost sine = sin(theta);
float cosine = cos(theta);
vector newAxis = new vector;
newAxis.x = cosine * dist .x + sine * dist .y;
newAxis.y = cosine * dist .y - sine * dist .x;
// Converted velocities
vector[] vTemp = {
new vector(), new vector() };
vTemp[0].x = cosine * agent.velocity.x + sine * agent.velocity.y;
vTemp[0].y = cosine * agent.velocity.y - sine * agent.velocity.x;
vTemp[1].x = cosine * current.velocity.x + sine * current.velocity.y;
vTemp[1].y = cosine * current.velocity.y - sine * current.velocity.x;
スタック上の好奇心数学オタクがあります望んにあります。..
おそらく[box2d](http://box2d.org/)や[chipmunk](http://chipmunk-physics.net/)のような物理エンジンを研究していますか? – nornagon
私はすべてがセットアップされている、私は比較的簡単にすべき角度を持っています。変換された軸は、私が知っている角度で衝突が発生することを意味し、私はそれを使って何かをする必要があります。 – Blue42
あなたは確かですか? 「剛性の」オブジェクトの衝突では、その力は巨大ですが簡単です。重要なことは、衝突後のオブジェクトの速度、速度、効果です。私はそれを剛体で回転しない円とします。弾性または非弾性? – Beta