/// <summary> /// Check if the target is within the angle to be fired at and then fire at them /// </summary> private void Fire() { (float angleHorz, float angleVert) = EnemyOperations.AngleToTarget(transform, _target.transform); if (angleHorz < _viewAreaHorz && angleVert < _viewAreaVert) { SpawnProjectile(); _animator.Fire(); _fireTimer = 0.0f; } }
/// <summary> /// Check if the player is within range to be fired at and then fire /// </summary> /// <returns>True if the enemy was able to fire at the player</returns> public bool Fire() { (float angleHorz, float angleVert) = EnemyOperations.AngleToTarget(transform, _player.transform); if (angleHorz < _fieldOfViewHorizontal && angleVert < _fieldOfViewVertical) { CreateProjectile(); _firedLastTurn = true; return(true); } return(false); }
/// <summary> /// Check if the player is within a certain field of view and range /// </summary> /// <param name="viewDistance">The maximum distance the enemy can see</param> /// <param name="viewHorz">The enemy's field of view horizontally</param> /// <param name="viewVert">The enemy's field of view vertically</param> /// <returns>True if the player is visible</returns> public bool PlayerInView(float viewDistance, float viewHorz, float viewVert) { // Check if an object is visible in the direction of the player from the enemy RaycastHit playerHit; if (Physics.Raycast(transform.position, _player.transform.position - transform.position, out playerHit, viewDistance)) { Transform target = playerHit.transform; // Check if the detected object is the player if (target.CompareTag("Player")) { (float angleHorz, float angleVert) = EnemyOperations.AngleToTarget(transform, _player.transform); // Check if the player is in front of the enemy within a line of sight if (angleHorz < viewHorz && angleVert < viewVert) { return(true); } } } return(false); }