void DetermineMoveSpeed() { if (enemyScript.isDead == false) { if ((enemySightScript.CanPlayerBeSeen() == true && enemyScript.distanceToPlayer <= stoppingDistance && !isHacked) || currentState == State.Idle || (currentState == State.Attack && enemyToAttack != null && currentTarget == enemyToAttack && Vector2.Distance(transform.position, enemyToAttack.position) <= stoppingDistance)) { moveSpeed = noSpeed; isRunning = false; isWalking = false; } else if (enemyScript.distanceToPlayer > stoppingDistance && player.isDead == false && playerPositionKnown == true || (currentState == State.Attack && currentTarget == enemyToAttack) || playerPositionKnown == true && enemySightScript.CanPlayerBeSeen() == false || currentState == State.CheckSound || currentState == State.Alert || currentState == State.SpreadOut) { moveSpeed = runSpeed; isRunning = true; isWalking = false; } else { moveSpeed = walkSpeed; isRunning = false; isWalking = true; } anim.SetFloat("moveSpeed", moveSpeed); anim.SetBool("isRunning", isRunning); anim.SetBool("isWalking", isWalking); } }
void EnemyArmRotation() { if (enemyMovementScript.currentTarget != null) { Vector3 playerPosition = player.transform.position; Vector3 enemyPosition = enemy.transform.position; Vector3 difference = enemyMovementScript.currentTarget.position - enemyPosition; // Subtracting the enemy's position from the player's position difference.Normalize(); // Normalize the vector. Meaning that the sum of the vector will be equal to 1. if (enemyMovementScript.isHacked) { if (enemyMovementScript.currentTarget == enemyMovementScript.enemyToAttack) { float rotationZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg; // Find the angle in degrees. transform.rotation = Quaternion.Euler(0f, 0f, (rotationZ + enemyRotationOffset)); } } else if (enemySightScript.CanPlayerBeSeen() == true) { float rotationZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg; // Find the angle in degrees. transform.rotation = Quaternion.Euler(0f, 0f, (rotationZ + enemyRotationOffset)); } else { transform.rotation = Quaternion.Euler(0f, 0f, 0f); } } else { transform.rotation = Quaternion.Euler(0f, 0f, 0f); } }
void CheckIfShooting() { if (enemyScript.isDead == false && enemyMovementScript.currentState == EnemyMovement.State.Attack) { if ((enemySightScript.CanPlayerBeSeen() == true && enemyScript.distanceToPlayer <= maxShootDistance) || (enemyMovementScript.currentTarget != null && enemyMovementScript.currentTarget == enemyMovementScript.enemyToAttack && Vector2.Distance(enemyMovementScript.transform.position, enemyMovementScript.currentTarget.position) <= maxShootDistance)) { isAbleToShoot = true; } else { isAbleToShoot = false; } if (isCoolingDown == false && isAbleToShoot == true && currentAmmoAmount > 0) { if (isAutomatic == false) // For semi-auto guns { coolDownTime = semiAutoCoolDownTime; StartCoroutine(EnemyShoot()); } else if (isAutomatic == true) // For automatic guns { coolDownTime = autoCoolDownTime; StartCoroutine(EnemyShoot()); } } } }
void OnTriggerStay2D(Collider2D collision) { playerEquippedWeapon = GameObject.FindGameObjectWithTag("EquippedWeapon").GetComponent <Weapon>(); if (collision.gameObject.tag == "SoundTrigger" && enemyMovementScript.currentState != EnemyMovement.State.Attack && !enemyMovementScript.isHacked) { if (enemySightScript.CanPlayerBeSeen() == false && enemyScript.isDead == false) { soundTriggerColliderOrigin = collision.gameObject.transform; soundTriggerColliderParent = collision.gameObject.transform.root; if (soundTriggerColliderParent.tag == "Player" && playerEquippedWeapon.isSilenced == false) { soundTriggerColliderRoom = soundTriggerColliderParent.gameObject.GetComponent <PlayerController>().currentRoom; soundTriggerColliderFloorLevel = soundTriggerColliderParent.gameObject.GetComponent <PlayerController>().currentFloorLevel; soundTriggerColliderRoomNumber = soundTriggerColliderParent.gameObject.GetComponent <PlayerController>().currentRoomNumber; enemyMovementScript.currentState = EnemyMovement.State.CheckSound; } else if (soundTriggerColliderParent.tag == "Enemy" && soundTriggerColliderParent.GetComponentInChildren <EnemyWeapon>().isSilenced == false) { soundTriggerColliderRoom = soundTriggerColliderParent.gameObject.GetComponent <EnemyMovement>().currentRoom; soundTriggerColliderFloorLevel = soundTriggerColliderParent.gameObject.GetComponent <EnemyMovement>().currentFloorLevel; soundTriggerColliderRoomNumber = soundTriggerColliderParent.gameObject.GetComponent <EnemyMovement>().currentRoomNumber; enemyMovementScript.currentState = EnemyMovement.State.CheckSound; } } } }