AI Command Lab // Flight Simulator
4F: Method Extraction
Initial AI Output (Fragile)
// AI-Generated Code: Hard to scan and audit
void Update() {
// Audit Fail: The main flight loop is cluttered with low-level math.
float d = Vector3.Distance(transform.position, target.position);
if (d < 10f && !Physics.Linecast(transform.position, target.position)) {
if (ammo > 0) {
FireWeapon();
}
}
}
Initial AI Prompt
"You ask the AI: "Make the enemy attack if it's close enough and not obstructed.""
Pilot Comm Link
Mission Objective: Use Native Arrays and the Job System for high-performance data processing.
Optimized Protocol
void Update() {
// Corrected: The high-level intent is instantly clear.
if (CanSeeTarget() && ammo > 0) {
FireWeapon();
}
}
// Extracted logic is now safely tucked away in its own hangar.
bool CanSeeTarget() {
float distance = Vector3.Distance(transform.position, target.position);
bool isObstructed = Physics.Linecast(transform.position, target.position);
return distance < 10f && !isObstructed;
}