IEnumerator <float> AICo() { yield return(Timing.WaitForSeconds(1 + Random.value * 1)); float rageTimer = 0.0f; while (true) { bool recentlySeenPlayer = mySenses_.GetPlayerLatestKnownPositionAge() < 2.0f; DefaultProjectiles.EnableEmission = recentlySeenPlayer; if (recentlySeenPlayer) { rageTimer += Time.deltaTime; if (rageTimer > (me_.LifePct * 4) && me_.LifePct < 0.8f) { // Telegraph to player enemyScript_.gameObject.layer = SceneGlobals.Instance.EnemyLayer; enemyScript_.EnableAiPath(false); AudioManager.Instance.PlaySfxClip(AppearSound, maxInstances: 3, 0, 1.5f); myMovement_.StopMove(); DefaultProjectiles.EnableEmission = false; var rageEmission = RageTelegraphParticles.emission; rageEmission.enabled = true; yield return(Timing.WaitForSeconds(1)); rageEmission.enabled = false; // Rage Vector2 playerDir = (AiBlackboard.Instance.PlayerPosition - transform_.position).normalized; myPhysics_.AddForce(playerDir * 200); rageTimer = 0; yield return(Timing.WaitForSeconds(2)); // Stop rage MapScript.Instance.TriggerExplosion(transform_.position, 2.85f, false, me_, damageSelf: false); enemyScript_.gameObject.layer = SceneGlobals.Instance.EnemyNoWallsLayer; enemyScript_.EnableAiPath(true); yield return(Timing.WaitForSeconds(0.3f)); } } myMovement_.MoveTo(AiBlackboard.Instance.PlayerPosition); yield return(0); } }
IEnumerator <float> AICo() { while (true) { if (me_.IsDead) { body_.drag = 2; body_.angularDrag = 3; yield break; } float dt = Time.deltaTime; float time = Time.time; var myPos = transform_.position; float velocityMagnitude = body_.velocity.magnitude; if (velocityMagnitude > MaxVelocity) { body_.velocity = Vector3.ClampMagnitude(body_.velocity, MaxVelocity); } float rotationSpeed = 90 + (velocityMagnitude * 100); rotation_ -= dt * rotationSpeed; rendererTransform_.rotation = Quaternion.Euler(0, 0, rotation_); var playerPos = AiBlackboard.Instance.PlayerPosition; var diff = playerPos - myPos; float sqrDistance = AttractDistance * AttractDistance; if (diff.sqrMagnitude < sqrDistance) { if (!isCharging_ && time > nextChargeSoundCd_) { AudioManager.Instance.PlaySfxClip(ChargeSound, 1); nextChargeSoundCd_ = time + ChargeSoundCooldown + Random.value; } var direction = diff.normalized; myPhysics_.AddForce(direction * AttractPower, ForceMode2D.Force); isCharging_ = true; } else { isCharging_ = false; } yield return(0); } }
IEnumerator <float> AICo() { yield return(Timing.WaitForSeconds(2)); // 1) Follow player until damaged a bit while (me_.LifePct > 0.95) { myMovement_.MoveTo(AiBlackboard.Instance.PlayerPosition); yield return(0); } // 2) Call for help myMovement_.StopMove(); shield_.gameObject.SetActive(true); yield return(Timing.WaitForSeconds(1.0f)); AudioManager.Instance.PlaySfxClip(AppearSound, maxInstances: 3, 0, 0.8f); yield return(Timing.WaitForSeconds(0.2f)); AudioManager.Instance.PlaySfxClip(AppearSound, maxInstances: 3, 0, 1.5f); var rageEmission = RageTelegraphParticles.emission; rageEmission.enabled = true; yield return(Timing.WaitForSeconds(2.5f)); rageEmission.enabled = false; GameEvents.RaiseGolemKingCallForHelp(); yield return(Timing.WaitForSeconds(5.0f)); // 3) Standard loop float rageTimer = 0.0f; float shieldEnd = Time.unscaledTime + 20.0f; while (true) { if (Time.unscaledTime > shieldEnd && shield_.gameObject.activeInHierarchy) { shield_.gameObject.SetActive(false); } bool recentlySeenPlayer = mySenses_.GetPlayerLatestKnownPositionAge() < 2.0f; if (recentlySeenPlayer) { rageTimer += Time.deltaTime; if (rageTimer > (me_.LifePct * 4) && me_.LifePct < 0.8f) { // Telegraph to player enemyScript_.gameObject.layer = SceneGlobals.Instance.EnemyLayer; enemyScript_.EnableAiPath(false); AudioManager.Instance.PlaySfxClip(AppearSound, maxInstances: 3, 0, 1.4f); myMovement_.StopMove(); rageEmission.enabled = true; yield return(Timing.WaitForSeconds(1)); rageEmission.enabled = false; // Rage Vector2 playerDir = (AiBlackboard.Instance.PlayerPosition - transform_.position).normalized; myPhysics_.AddForce(playerDir * 200); rageTimer = 0; yield return(Timing.WaitForSeconds(2)); // Stop rage MapScript.Instance.TriggerExplosion(transform_.position, 3.9f, false, me_, damageSelf: false); enemyScript_.gameObject.layer = SceneGlobals.Instance.EnemyNoWallsLayer; enemyScript_.EnableAiPath(true); yield return(Timing.WaitForSeconds(0.3f)); } } myMovement_.MoveTo(AiBlackboard.Instance.PlayerPosition); yield return(0); } }