Ejemplo n.º 1
0
 protected virtual void ShootAtPlayer()
 {
     if (PlayerPosUtil.GetAngleToPlayer(transform) <= shootAngle && hasPlayerInSight)
     {
         weapon.Fire();
     }
 }
    /// <summary>
    /// Calculates direction of player when projectile hits
    /// </summary>
    private Vector2?GetTargetDirection()
    {
        float?  timeTillImpact = PlayerPosUtil.GetDistanceFromPlayer(transform) / weapon.GetProjectileVelocity();
        Vector2?target         = PlayerPosUtil.CalculateFuturePosition(timeTillImpact);

        return((target == null) ? null : target - transform.position);
    }
    private float?GetAngleToTarget()
    {
        if (weapon == null || weapon is MeleeWeapon)
        {
            return(PlayerPosUtil.GetAngleToPlayer(transform));
        }
        Vector2?targetDirection = GetTargetDirection();

        return(Vector2.Angle(targetDirection.Value, transform.right));
    }
Ejemplo n.º 4
0
 public override void CloseCombatAttack()
 {
     if (PlayerPosUtil.GetDistanceFromPlayer(transform) > minCloseCombatRange)
     {
         return;
     }
     if (weapon != null)
     {
         weapon.Fire();
     }
     else
     {
         base.CloseCombatAttack();
     }
 }
Ejemplo n.º 5
0
    public void FollowPlayer(Enemy enemy, Player player)
    {
        float attackRange = (enemy.Weapon is FireArm) ? enemy.preferredAttackRange : 0f;

        if (enemy.HasPlayerInSight && (PlayerPosUtil.GetDistanceFromPlayer(enemy.transform) < attackRange))
        {
            enemy.ChangeDestination(null, 0);
        }
        else
        {
            enemy.ChangeDestination(enemy.LastKnownPlayerPosition, enemy.maxVelocity);
        }
        if (Vector2.Distance(enemy.transform.position, enemy.LastKnownPlayerPosition) < 0.5f)
        {
            reachedLastKnownPos = true;
        }
        if (reachedLastKnownPos == false)
        {
            enemy.LookAtPlayer();
        }
    }
Ejemplo n.º 6
0
    /// <summary>
    /// Checks if player is in the line of sight
    /// </summary>
    protected virtual void CheckLineOfSight()
    {
        // perform check
        bool oldStatus = hasPlayerInSight;

        hasPlayerInSight = PlayerPosUtil.GetIsPlayerInSight(transform, visionAngle, visionRange);
        statusChanged    = (oldStatus == hasPlayerInSight);

        if (hasPlayerInSight)
        {
            lastKnownPlayerPosition = player.transform.position;
        }

        // react
        if (hasPlayerInSight && awarenessSystem.Awareness != awarenessSystem.MaxAwareness)
        {
            awarenessSystem.Awareness = awarenessSystem.MaxAwareness;
        }
        else if (statusChanged && !hasPlayerInSight && !awarenessSystem.IsCoolingDown && awarenessSystem.Awareness != 0)
        {
            awarenessSystem.StartCooldown();
        }
    }
Ejemplo n.º 7
0
    /// <summary>
    /// Makes enemy look towards player
    /// </summary>
    public virtual void LookAtPlayer()
    {
        float?angle = PlayerPosUtil.GetSignedAngleToPlayer(transform);

        RotateEnemyByAngle(angle);
    }