//---------------------------------------------------------------------------------------------- // 更新処理 //---------------------------------------------------------------------------------------------- public override void OnUpdate(AutoPilot ap) { // 敵選択(0.5秒以上押し続けると解除) ap.SelectEnemy(KeyCode.Mouse1); // エナジーが10%未満になったら捕捉を中止する if (ap.GetEnergy() < 10) { ap.ForgetEnemy(); } // 情報取得&表示 float dist = ap.GetEnemyDistance(); ap.Print(0, "Enemy : " + ap.GetEnemyName()); ap.Print(1, "Distance : " + dist); // 選択中の敵が600m以内ならエイミング if (dist < 600f) { Vector3 relVel = ap.GetEnemyVelocity() - ap.GetVelocity() * 0.5f; // 相対速度 Vector3 estPos = ap.GetEnemyPosition() + relVel * dist * 0.006f; // 着弾予測座標 ap.Aim(estPos); // 選択中の敵が500m以内なら射撃アクション実行 if (dist < 500f) { ap.StartAction("CannonA", 1); } } }
//---------------------------------------------------------------------------------------------- // Update //---------------------------------------------------------------------------------------------- public override void OnUpdate(AutoPilot ap) { // Attack int energy = ap.GetEnergy(); if (energy > 20 && Input.GetMouseButton(0)) { ap.StartAction("ATK1", -1); } else { ap.EndAction("ATK1"); } if (Input.GetMouseButtonDown(2)) { if (energy > 10 && !sword) { ap.StartAction("ATK3", -1); sword = true; } else { ap.EndAction("ATK3"); sword = false; } } if (energy > 10 && jetStriker) { ap.StartAction("ATK3", 1); } if (energy <= 10) { ap.EndAction("ATK3"); sword = false; } if (energy > 10 && Input.GetMouseButtonDown(1) && !missile) { ap.StartAction("ATK2", -1); missile = true; } else if (Input.GetMouseButtonDown(1) || energy <= 10) { ap.EndAction("ATK2"); missile = false; } //Move if (!flightMode) { //Human Mode if (Input.GetKey(KeyCode.W)) { ap.StartAction("w", 1); } if (Input.GetKey(KeyCode.A)) { ap.StartAction("a", 1); } if (Input.GetKey(KeyCode.S)) { ap.StartAction("s", 1); } if (Input.GetKey(KeyCode.D)) { ap.StartAction("d", 1); } if (Input.GetKey(KeyCode.Space)) { ap.StartAction("up", 1); } if (Input.GetKey(KeyCode.F)) { ap.StartAction("down", 1); } if ((Input.GetKeyDown(KeyCode.Alpha1) && aim) || Input.GetKeyDown(KeyCode.Q)) { ap.EndAction("AIM1"); aim = false; } else if (Input.GetKeyDown(KeyCode.Alpha1) && !aim || Input.GetKeyUp(KeyCode.Q)) { ap.StartAction("AIM1", -1); aim = true; } if (Input.GetKeyDown(KeyCode.Alpha2)) { ap.StartAction("change", -1); ap.EndAction("AIM1"); flightMode = true; } if (Input.GetKeyDown(KeyCode.E)) { ap.StartAction("change", -1); ap.EndAction("AIM1"); flightMode = true; autoPilot = true; jetStriker = true; } else { jetStriker = false; } } else { //Fighter Mode if (jetStriker && Input.GetKeyDown(KeyCode.E)) { jetStriker = false; autoPilot = false; } else if (!jetStriker && Input.GetKeyDown(KeyCode.E)) { jetStriker = true; autoPilot = true; ap.ForgetEnemy(); } if (Input.GetKey(KeyCode.W) || jetStriker) { ap.StartAction("FMforth", 1); } if (Input.GetKey(KeyCode.A)) { ap.StartAction("a", 1); } if (Input.GetKey(KeyCode.S)) { ap.StartAction("FMback", 1); } if (Input.GetKey(KeyCode.D)) { ap.StartAction("d", 1); } if (Input.GetKey(KeyCode.Space)) { ap.StartAction("FMup", 1); } if (Input.GetKey(KeyCode.F)) { ap.StartAction("FMdown", 1); } if (Input.GetKeyDown(KeyCode.Alpha2)) { ap.EndAction("change"); flightMode = false; ap.StartAction("AIM1", -1); aim = true; } } //AutoAim float enemyDistance = ap.GetEnemyDistance(); float enemyAngleR = ap.GetEnemyAngleR(); float enemyAngleU = ap.GetEnemyAngleU(); Vector3 enemyVelocity = ap.GetEnemyVelocity() - ap.GetVelocity(); enemyHeight = ap.GetEnemyPosition().y; selfHeight = ap.GetPosition().y; //AutoPilot if (autoPilot) { if (!ap.CheckEnemy()) { ap.SearchEnemy(); } aim = true; //TargetReset if (Input.GetKeyDown(KeyCode.Alpha4)) { ap.ForgetEnemy(); } ap.SelectEnemy(KeyCode.Alpha4); if (ap.CheckEnemy()) { newHeight = Mathf.Abs(enemyHeight - selfHeight); } else { newHeight = 0; } if (newHeight > heightSwitch && !Input.GetKey(KeyCode.Q)) { aimMode = 1; if (!flightMode) { ap.StartAction("AIM1", -1); if (enemyAngleR < -15 && !Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.D)) { ap.StartAction("a", 1); } if (enemyAngleR > 15 && !Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.D)) { ap.StartAction("d", 1); } } else { if (enemyAngleR < -5 && !Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.D)) { ap.StartAction("a", 1); } if (enemyAngleR > 5 && !Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.D)) { ap.StartAction("d", 1); } if (enemyHeight - selfHeight > heightSwitch && !Input.GetKey(KeyCode.Space) && !Input.GetKey(KeyCode.F)) { ap.StartAction("FMup", 1); } if (enemyHeight - selfHeight < -heightSwitch && !Input.GetKey(KeyCode.Space) && !Input.GetKey(KeyCode.F)) { ap.StartAction("FMdown", 1); } } } else if (!Input.GetKey(KeyCode.Q)) { aimMode = 2; if (!flightMode) { ap.StartAction("AIM1", -1); if (enemyAngleR < -15 && !Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.D)) { ap.StartAction("a", 1); } if (enemyAngleR > 15 && !Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.D)) { ap.StartAction("d", 1); } } else { if (enemyAngleR < -5 && !Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.D)) { ap.StartAction("a", 1); } if (enemyAngleR > 5 && !Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.D)) { ap.StartAction("d", 1); } if (enemyHeight - selfHeight < heightSwitch && enemyHeight - selfHeight > -heightSwitch && !Input.GetKey(KeyCode.Space) && !Input.GetKey(KeyCode.F)) { if (ap.GetVelocity().y < -10) { ap.StartAction("FMup", 1); } if (ap.GetVelocity().y > 10) { ap.StartAction("FMdown", 1); } } } } else { aimMode = 0; ap.EndAction("AIM1"); } if (Input.GetKeyDown(KeyCode.Alpha3) || (Input.GetKeyDown(KeyCode.Alpha1) && aim)) { ap.ForgetEnemy(); autoPilot = false; jetStriker = false; if (!flightMode) { ap.StartAction("AIM1", -1); } } if (aimMode == 1 || aimMode == 2) { // Aim & Attack Vector3 ev = ap.GetEnemyVelocity() - ap.GetVelocity(); float ed = enemyDistance * 0.003f; Vector3 mv = ap.MulVec(ev, ed); //AutoAim Vector3 estPos = ap.AddVec(ap.GetEnemyPosition(), mv); ap.Aim(estPos); } } else { aimMode = 0; if (Input.GetKeyDown(KeyCode.Alpha3)) { autoPilot = true; } } if (friendFlg) { if (!ap.CheckFriend()) { ap.SearchFriend(""); } if (!ap.CheckEnemy() && ap.CheckFriend()) { searchAction = "SearchFriend"; int ang = ap.GetFriendAngleR(); if (ang > 15) { ap.StartAction("d", 1); } else if (ang < -15) { ap.StartAction("a", 1); } friendCount++; if (Input.GetKeyDown(KeyCode.Alpha5) || friendCount > 199) { friendFlg = false; friendCount = 0; ap.ForgetFriend(); searchAction = "Standby"; } } } else { if (Input.GetKeyDown(KeyCode.Alpha5)) { friendFlg = true; searchAction = "SearchFriend"; } } //AGD if (flightMode && (ap.GetGroundClearance() > 10 || Input.GetKey(KeyCode.Alpha6))) { ap.StartAction("AGD", 1); } //Display Information ap.Print(0, "Enemy : " + ap.GetEnemyName()); ap.Print(1, "Distance : " + enemyDistance); ap.Print(2, "AngleR : " + ap.GetEnemyAngleR()); ap.Print(3, "AimMode : " + aimMode); ap.Print(4, "EnemyHeight : " + ap.GetEnemyPosition().y); ap.Print(5, "SelfHeight : " + ap.GetPosition().y); ap.Print(6, "NewHeight : " + newHeight); ap.Print(7, "SearchAction : " + searchAction); ap.Print(8, "UpDownVel : " + ap.GetVelocity().y); }
//---------------------------------------------------------------------------------------------- // 更新処理 //---------------------------------------------------------------------------------------------- public override void OnUpdate(AutoPilot ap) { //索敵(前方優先で近い敵を選択) if (ap.CheckEnemy() == false && (aimMode == 2 || aimMode == 3 || aimMode == 4)) { ap.SearchEnemy(); } int enemyDistance = ap.GetEnemyDistance(); enemyHeight = ap.GetEnemyPosition().y; selfHeight = ap.GetPosition().y; if (ap.CheckEnemy() == true) { newHeight = (enemyHeight - selfHeight) * 2; } //対地対空機銃自動エイミングモード if (Input.GetKeyDown(KeyCode.Alpha3)) { autoAim = true; if (newHeight > heightSwitch) { aimMode = 4; ap.StartAction("AIM1", -1); ap.EndAction("AIM2"); } else { aimMode = 3; ap.StartAction("AIM2", -1); ap.EndAction("AIM1"); } } newHeight = (enemyHeight - selfHeight) * 2; if (newHeight > heightSwitch && oldHeight <= heightSwitch && autoAim) { aimMode = 4; ap.StartAction("AIM1", -1); ap.EndAction("AIM2"); } if (newHeight < heightSwitch && oldHeight >= heightSwitch && autoAim) { aimMode = 3; ap.StartAction("AIM2", -1); ap.EndAction("AIM1"); } //ターゲットリセット if (Input.GetKeyDown(KeyCode.Alpha2) || Input.GetKeyDown(KeyCode.Alpha3)) { ap.ForgetEnemy(); } ap.SelectEnemy(KeyCode.Alpha2); ap.SelectEnemy(KeyCode.Alpha3); // 攻撃 int energy = ap.GetEnergy(); if (energy > 10 && Input.GetMouseButton(0)) { ap.StartAction("ATK1", -1); } else { ap.EndAction("ATK1"); } if (energy > 40 && Input.GetMouseButton(1)) { ap.StartAction("ATK2", -1); } else { ap.EndAction("ATK2"); } if (energy > 5 && Input.GetMouseButton(2)) { ap.StartAction("ATK3", -1); } else { ap.EndAction("ATK3"); } //エイムモード if (Input.GetKeyDown(KeyCode.Alpha1)) { aimMode = 1; //手動モード ap.StartAction("AIM1", -1); ap.EndAction("AIM2"); autoAim = false; } else if (Input.GetKeyDown(KeyCode.Alpha2)) { aimMode = 2; //榴弾モード ap.StartAction("AIM2", -1); ap.EndAction("AIM1"); autoAim = false; } else if (aimChange == 3) { aimMode = 3; //対地モード ap.StartAction("AIM2", -1); ap.EndAction("AIM1"); } else if (aimChange == 4) { aimMode = 4; //対空モード ap.StartAction("AIM1", -1); ap.EndAction("AIM2"); } else if (Input.GetKeyDown(KeyCode.Alpha4)) { aimMode = 0; //休止モード ap.EndAction("AIM1"); ap.EndAction("AIM2"); autoAim = false; } //情報表示 ap.Print(0, "Position : " + ap.GetPosition()); ap.Print(1, "Pitch : " + ap.GetPitch()); ap.Print(2, "Direction : " + ap.GetDirection()); ap.Print(3, "Back : " + ap.GetBank()); // エイム & 攻撃(敵の速度と距離を考慮して目標座標を補正) Vector3 ev = ap.GetEnemyVelocity() - ap.GetVelocity(); float ed = enemyDistance * 0.003f; Vector3 mv = ap.MulVec(ev, ed); if (aimMode == 2) { //榴弾オートエイム Vector3 estPos = ap.AddVec(ap.GetEnemyPosition(), mv); Vector3 mv2 = ap.MulVec(ap.GetGravity(), enemyDistance * enemyDistance * 0.006f); ap.Aim(ap.SubVec(estPos, mv2)); } if (aimMode == 3 || aimMode == 4) { //機銃オートエイム Vector3 estPos = ap.AddVec(ap.GetEnemyPosition(), mv); ap.Aim(estPos); } oldHeight = newHeight; }
//---------------------------------------------------------------------------------------------- // 更新処理 //---------------------------------------------------------------------------------------------- public override void OnUpdate(AutoPilot ap) { //索敵(前方優先で近い敵を選択) if (ap.CheckEnemy() == false && (aimMode == 2 || aimMode == 3 || aimMode == 4)) { ap.SearchEnemy(); } int enemyDistance = ap.GetEnemyDistance(); enemyHeight = ap.GetEnemyPosition().y; selfHeight = ap.GetPosition().y; if (ap.CheckEnemy()) { newHeight = Mathf.Abs(enemyHeight - selfHeight); } else { newHeight = 0f; } //対地対空機銃自動エイミングモード if (Input.GetKeyDown(KeyCode.Alpha2)) { autoAim = true; if (newHeight > heightSwitch) { aimMode = 4; ap.StartAction("AIM1", -1); ap.EndAction("AIM2"); } else { aimMode = 3; ap.StartAction("AIM2", -1); ap.EndAction("AIM1"); } } newHeight = (enemyHeight - selfHeight) * 2; if (newHeight > heightSwitch && oldHeight <= heightSwitch && autoAim) { aimMode = 4; ap.StartAction("AIM1", -1); ap.EndAction("AIM2"); } if (newHeight < heightSwitch && oldHeight >= heightSwitch && autoAim) { aimMode = 3; ap.StartAction("AIM2", -1); ap.EndAction("AIM1"); } //ターゲットリセット if (Input.GetKeyDown(KeyCode.Alpha2) || Input.GetKeyDown(KeyCode.Alpha3)) { ap.ForgetEnemy(); } ap.SelectEnemy(KeyCode.Alpha2); ap.SelectEnemy(KeyCode.Alpha3); // 攻撃 int energy = ap.GetEnergy(); if (energy > 10 && Input.GetMouseButton(0)) { ap.StartAction("ATK1", -1); } else { ap.EndAction("ATK1"); } if (energy > 15 && Input.GetMouseButton(1)) { ap.StartAction("ATK2", -1); } else { ap.EndAction("ATK2"); } if (!missile && energy > 5 && Input.GetMouseButtonDown(2)) { ap.StartAction("ATK3", -1); missile = true; } else if (missile && (Input.GetMouseButtonDown(2) || energy < 5)) { ap.EndAction("ATK3"); missile = false; } //エイムモード if (Input.GetKeyDown(KeyCode.Alpha1)) { aimMode = 1; //手動モード ap.StartAction("AIM1", -1); ap.EndAction("AIM2"); autoAim = false; } else if (aimChange == 3) { aimMode = 3; //対地モード ap.StartAction("AIM2", -1); ap.EndAction("AIM1"); } else if (aimChange == 4) { aimMode = 4; //対空モード ap.StartAction("AIM1", -1); ap.EndAction("AIM2"); } else if (Input.GetKeyDown(KeyCode.Alpha4)) { aimMode = 0; //休止モード ap.EndAction("AIM1"); ap.EndAction("AIM2"); autoAim = false; } //情報表示 ap.Print(0, "Enemy : " + ap.GetEnemyName()); ap.Print(1, "Distance : " + enemyDistance); ap.Print(2, "AngleR : " + ap.GetEnemyAngleR()); ap.Print(3, "AimMode : " + aimMode); ap.Print(4, "EnemyHeight : " + ap.GetEnemyPosition().y); ap.Print(5, "SelfHeight : " + ap.GetPosition().y); // エイム & 攻撃(敵の速度と距離を考慮して目標座標を補正) Vector3 ev = ap.GetEnemyVelocity() - ap.GetVelocity(); float ed = enemyDistance * 0.003f; Vector3 mv = ap.MulVec(ev, ed); if (aimMode == 3 || aimMode == 4) { //機銃オートエイム Vector3 estPos = ap.AddVec(ap.GetEnemyPosition(), mv); ap.Aim(estPos); } oldHeight = newHeight; }
//---------------------------------------------------------------------------------------------- // 更新処理 //---------------------------------------------------------------------------------------------- public override void OnUpdate(AutoPilot ap) { // 攻撃 int energy = ap.GetEnergy(); //エンジン if (jetPower > 0) { if (Input.GetKeyDown(JetDown)) { jetPower--; } } if (jetPower < 4) { if (Input.GetKeyDown(JetUp)) { jetPower++; } } if (jetPower == 0 && Input.GetKeyDown(JetToggle)) { jetPower = 3; } else if (jetPower == 1) { ap.StartAction("Jet1", 1); if (Input.GetKeyDown(JetToggle)) { jetPower = 3; } } else if (jetPower == 2) { ap.StartAction("Jet2", 1); if (Input.GetKeyDown(JetToggle)) { jetPower = 3; } } else if (jetPower == 3) { ap.StartAction("Jet3", 1); if (Input.GetKeyDown(JetToggle)) { jetPower = 0; } } else if (jetPower == 4) { ap.StartAction("Boost", 1); jetPower--; } // 子機起動 if (bit && Input.GetKeyDown(BitToggle)) { bit = false; autoAim = false; scope = 0; } else if (!bit && Input.GetKeyDown(BitToggle)) { bit = true; autoAim = true; scope = 2; } else if (autoAim && Input.GetKeyDown(AimToggle)) { autoAim = false; } else if (!autoAim && Input.GetKeyDown(AimToggle)) { autoAim = true; } else if (scope == 0 && Input.GetKeyDown(ScopeToggle)) { scope = 1; } else if (scope == 1 && Input.GetKeyDown(ScopeToggle)) { scope = 2; } else if (scope == 2 && Input.GetKeyDown(ScopeToggle)) { scope = 0; } if (bit) { ap.StartAction("Split", 1); } //ターゲットリセット if (Input.GetKeyDown(AimReset)) { ap.ForgetEnemy(); } //索敵(前方優先で近い敵を選択) if (ap.CheckEnemy() == false && autoAim) { ap.SearchEnemy(); } if (ap.CheckEnemy() && autoAim) { int enemyDistance = ap.GetEnemyDistance(); // エイム(敵の速度と距離を考慮して目標座標を補正) Vector3 ev = ap.GetEnemyVelocity() - ap.GetVelocity(); float ed = enemyDistance * 0.001f; Vector3 mv = ap.MulVec(ap.GetEnemyVelocity(), ed); Vector3 estPos = ap.AddVec(ap.GetEnemyPosition(), mv); ap.Aim(estPos); bit = true; //情報表示 ap.Print(3, "Enemy : " + ap.GetEnemyName()); ap.Print(4, "Distance : " + enemyDistance); ap.Print(5, "AngleR : " + ap.GetEnemyAngleR()); ap.Print(6, "AngleU : " + ap.GetEnemyAngleU()); } else if (!ap.CheckEnemy() && autoAim) { bit = false; //情報表示 ap.Print(5, "Enemy : None"); ap.Print(6, "Distance : None"); ap.Print(7, "AngleR : None"); ap.Print(8, "AngleU : None"); } else { //情報表示 ap.Print(5, "Enemy : None"); ap.Print(6, "Distance : None"); ap.Print(7, "AngleR : None"); ap.Print(8, "AngleU : None"); } //カメラ if (scope == 1) { ap.StartAction("Camera1", 1); } else if (scope == 2) { ap.StartAction("Camera2", 1); } //情報表示 ap.Print(0, "EnginePower : " + jetPower); ap.Print(1, "EnemyExist : " + ap.CheckEnemy()); ap.Print(2, "AimMode : " + autoAim); ap.Print(3, "CameraMode : " + scope); ap.Print(4, "BitMode : " + bit); //銃 if (energy > 10 && Input.GetKey(Wep1) && !autoAim) { ap.StartAction("Cannon", 1); } else if (energy > 10 && Input.GetKey(Wep1) && autoAim && ap.CheckEnemy() && (ap.GetEnemyAngleR() < 90 && ap.GetEnemyAngleR() > -90) && (ap.GetEnemyAngleU() < 45 && ap.GetEnemyAngleU() > -90)) { ap.StartAction("Cannon", 1); } }