はWikipediaのページTrajectory of a projectileによると、 "到達の角度"(あなたが知りたい角度)が計算されます。
はθ= 1/2 *アークサイン(GD /v²)
この式では、gは重力定数9.81、dは発射体が移動する距離、vはオブジェクトが投げられる速度です。これを計算するための
コードは次のようになります:
float ThrowAngle(Vector3 destination, float velocity)
{
const float g = 9.81f;
float distance = Vector3.Distance(transform.position, destination);
//assuming you want degrees, otherwise just drop the Rad2Deg.
return Mathf.Rad2Deg * (0.5f * Asin((g*distance)/Mathf.Pow(velocity, 2f)));
}
これはあなたのゲーム内に存在など全く空気抵抗がないと仮定すると角度を与えるだろう。 あなたの目的地とあなたの「投げる地点」が同じ高さにない場合は、最初に両方ともy = 0に設定したい場合があります。そうでない場合は、エラーが発生する可能性があります。
EDIT:あなたの出発点は、先よりもアップ高いことを考慮すると
、同じページから、この式は動作するはずです:
θ=アークタンジェント(v²(+/-)√(V (gx²+ 2yv2))/ gx)
ここで、xは距離または距離で、yは(発射地点からの)高度です。
コード:
float ThrowAngle(Vector3 start, Vector3 destination, float v)
{
const float g = 9.81f;
float xzd = Mathf.Sqrt(Mathf.Pow(destination.x - start.x, 2) + Mathf.Pow(destination.z - start.z, 2));
float yd = destination.y - start.y;
//assuming you want degrees, otherwise just drop the Rad2Deg. Split into two lines for better readability.
float sqrt = (Mathf.Pow(v,4) - g * (g*Mathf.Pow(xzd,2) + 2*yd*Mathf.Pow(v,2))/g*xzd);
//you could also implement a solution which uses both values in some way, but I left that out for simplicity.
return Mathf.Atan(Mathf.Pow(v, 2) + sqrt);
}
ません両方が同じ高さにすることはできません。ボウリング(ボールの動き)と同じビデオで示されるように、ある高さで投影が開始され、目的地点が地上にあります。 – djkp
その記事には、y = 0で始まらないスローの部分とy = 0のランディング・ポイントがあります(下の点をy = 0として扱うでしょう。 = 0)正しい式を見つけるには右の図を見てください。 –
現在、回答を書いています。私に瞬間を与えてください。 –