Ingénieur en mécanique de jeu : Contrôleur de dérive spatiale
De Wikiprompt, l’encyclopédie libre de prompts
Ingénieur en mécanique de jeu : Contrôleur de dérive spatiale Invite système pour générer du code de mécaniques de jeu basées sur la physique, axé sur le mouvement newtonien et l'interception de projectiles avec des scripts C#.
Contenu du PromptEnregistrer
🌐
Ship inertia model:
- Mass (m) = 1.0 (normalized)
- Thrust acceleration (a_thrust) = 12.5 m/s²
- Drag coefficient (k_drag) = 0.08 s⁻¹
- Max speed (v_max) = 45 m/s
Velocity update per frame (dt):
v_new = v_old + (a_thrust * input_dir - k_drag * v_old) * dt
Clamp |v_new| ≤ v_max
Projectile logic:
- Projectile speed (p_speed) = 60 m/s (constant, independent of ship)
- Projectile initial velocity = ship_velocity + (fire_direction * p_speed)
- Projectile position update: p_pos += projectile_velocity * dt
- No gravity, no drag on projectile
Mathematical derivation for projectile interception (target at position T, velocity V_t, shooter at S, projectile speed p_speed):
Solve for time t:
|S + (V_ship + p_speed * dir) * t - (T + V_t * t)| = 0
Simplify to quadratic: |(V_ship - V_t + p_speed * dir) * t + (S - T)|² = 0
Let D = S - T, U = V_ship - V_t + p_speed * dir
Then: |U|² * t² + 2 * (U · D) * t + |D|² = 0
Solve for t using quadratic formula, take smallest positive root.
Performance-optimized C# script (Unity-style, no MonoBehaviour overhead):
```csharp
public struct ShipState {
public Vector2 pos;
public Vector2 vel;
}
public struct Projectile {
public Vector2 pos;
public Vector2 vel;
public bool active;
}
public static class CombatPhysics {
const float THRUST = 12.5f;
const float DRAG = 0.08f;
const float MAX_SPEED = 45f;
const float PROJ_SPEED = 60f;
const float DT = 0.016f; // fixed timestep
public static ShipState UpdateShip(ShipState s, Vector2 inputDir) {
Vector2 accel = inputDir * THRUST - s.vel * DRAG;
s.vel += accel * DT;
if (s.vel.magnitude > MAX_SPEED) s.vel = s.vel.normalized * MAX_SPEED;
s.pos += s.vel * DT;
return s;
}
public static Projectile FireProjectile(ShipState s, Vector2 fireDir) {
Projectile p;
p.pos = s.pos;
p.vel = s.vel + fireDir * PROJ_SPEED;
p.active = true;
return p;
}
public static void UpdateProjectile(ref Projectile p) {
p.pos += p.vel * DT;
}
public static float InterceptTime(Vector2 shooterPos, Vector2 shooterVel, Vector2 targetPos, Vector2 targetVel, Vector2 fireDir) {
Vector2 D = shooterPos - targetPos;
Vector2 U = shooterVel - targetVel + fireDir * PROJ_SPEED;
float a = Vector2.Dot(U, U);
float b = 2f * Vector2.Dot(U, D);
float c = Vector2.Dot(D, D);
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 = (t1 > 0f) ? t1 : t2;
return (t > 0f) ? t : -1f;
}
}
```
High-frequency collision polling: use a fixed timestep of 1/60s (or 1/120s for precision), iterate all active projectiles against all targets each step, using spatial hash grid (cell size = 2 * max projectile speed * DT) to reduce pair checks. No raycasting - only discrete position updates with swept AABB check per step.
Connectez-vous pour voir le prompt complet
Continuer avec:
En vous connectant, vous acceptez nos Conditions et Confidentialité
Utilisation
Ce prompt est conçu pour être utilisé avec coding. Copiez le contenu ci-dessus et collez-le dans votre outil d’IA préféré.
Pour de meilleurs résultats, personnalisez les espaces réservés (indiqués par des crochets ou des majuscules) selon vos besoins.
Discussion
0 commentaires