ゲームメカニクスエンジニア:スペースドリフトコントローラー
フリーのプロンプト百科事典 Wikiprompt より
ゲームメカニクスエンジニア:スペースドリフトコントローラー 物理ベースのゲームメカニクスコード生成用システムプロンプト。ニュートン運動と投射物迎撃に焦点を当て、C#スクリプトを使用する。
プロンプト内容保存
🌐
トップダウンスペースドリフトコントローラを実装する。船は慣性を持ち、武器の発射速度は船の現在の移動ベクトルに相対的である。
コア移動ロジック:
- 船の加速度ベクトル a(t) は、スラスタ入力 u(t) に比例し、a(t) = u(t) * thrust_force / mass。
- 速度 v(t) は、v(t+dt) = v(t) + a(t) * dt で更新。ドリフトは減衰なし(真空空間)。
- 位置 p(t) は、p(t+dt) = p(t) + v(t) * dt。
- 最大速度制限は任意、clamp(v_magnitude, 0, max_speed) を適用。
投射物発射ロジック:
- 発射時の船の速度ベクトル v_ship を取得。
- 投射物の初期速度 v_projectile = v_ship + v_muzzle * direction。
- ここで v_muzzle は固定の発射速度(例:500 units/s)、direction は発射方向の単位ベクトル。
- 投射物はその後、慣性で直線運動(加速度なし)。
投射物迎撃の数学的導出:
- 目標の位置 P_target(t) = P_target0 + V_target * t。
- 投射物の位置 P_projectile(t) = P_projectile0 + V_projectile * t。
- 迎撃条件:|P_target(t) - P_projectile(t)| = 0。
- 解く:|(P_target0 - P_projectile0) + (V_target - V_projectile) * t| = 0。
- 二乗して:|D0 + ΔV * t|^2 = 0、ここで D0 = P_target0 - P_projectile0、ΔV = V_target - V_projectile。
- 展開:|D0|^2 + 2 * (D0 · ΔV) * t + |ΔV|^2 * t^2 = 0。
- 二次方程式:a = |ΔV|^2、b = 2 * (D0 · ΔV)、c = |D0|^2。
- 解 t = (-b ± sqrt(b^2 - 4ac)) / (2a)。正の実根が迎撃時間。最小の正の t を選択。
パフォーマンス最適化C#スクリプト(高頻度衝突ポーリング用):
```csharp
public class SpaceDriftController : MonoBehaviour {
public float thrustForce = 100f;
public float mass = 1f;
public float maxSpeed = 200f;
public float muzzleVelocity = 500f;
public float fixedDeltaTime = 0.01f; // 100Hzポーリング
private Vector2 velocity;
private Vector2 position;
void FixedUpdate() {
Vector2 input = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
Vector2 acceleration = input * thrustForce / mass;
velocity += acceleration * fixedDeltaTime;
if (velocity.magnitude > maxSpeed) {
velocity = velocity.normalized * maxSpeed;
}
position += velocity * fixedDeltaTime;
transform.position = position;
}
public Vector2 FireProjectile(Vector2 direction) {
Vector2 v_projectile = velocity + direction.normalized * muzzleVelocity;
return v_projectile; // 投射物の初期速度
}
public float InterceptTime(Vector2 targetPos, Vector2 targetVel, Vector2 projectilePos, Vector2 projectileVel) {
Vector2 D0 = targetPos - projectilePos;
Vector2 dV = targetVel - projectileVel;
float a = dV.sqrMagnitude;
float b = 2f * Vector2.Dot(D0, dV);
float c = D0.sqrMagnitude;
if (Mathf.Abs(a) < 1e-6f) {
if (Mathf.Abs(b) < 1e-6f) return -1f;
float t = -c / b;
return t > 0f ? t : -1f;
}
float disc = b * b - 4f * a * c;
if (disc < 0f) return -1f;
float sqrtDisc = Mathf.Sqrt(disc);
float t1 = (-b - sqrtDisc) / (2f * a);
float t2 = (-b + sqrtDisc) / (2f * a);
float t = Mathf.Min(t1, t2);
if (t < 0f) t = Mathf.Max(t1, t2);
return t > 0f ? t : -1f;
}
}
```
衝突ポーリング最適化:FixedUpdateで毎フレーム、全投射物と全目標のペアに対してInterceptTimeを計算し、最小正のtを検出。空間ハッシュグリッドで近接ペアのみを評価し、O(n)をO(k)に削減。投射物はプーリングで再利用し、GCアロケーションを回避。
ログインして完全なプロンプトを表示
次で続行:
ログインすると、次に同意したことになります: 利用規約 と プライバシーポリシー
使い方
このプロンプトは coding 向けに設計されています。上の内容をコピーして、お好みの AI ツールに貼り付けてください。
最良の結果を得るには、プレースホルダー(角括弧や大文字で示された部分)を具体的な要件に置き換えてください。
ノート
0 件のコメント