Ejemplo n.º 1
0
    public void Update()
    {
        var playerEyesight  = _player.GetEntity <EyesightEntity>();
        var playerSpottable = _player.GetEntity <SpottableEntity>();
        var playerPhysical  = _player.GetEntity <IPhysicalEntity>();

        foreach (var enemy in _enemies)
        {
            var enemySpottable = enemy.GetEntity <SpottableEntity>();

            enemySpottable.Spotted = IsSpotted(playerEyesight, enemySpottable);

            var enemyEyesight = enemy.GetEntity <EnemyEyesightEntity>();
            if (IsSpotted(enemyEyesight, playerSpottable))
            {
                enemyEyesight.PlayerTimeBeingSpotted += Time.deltaTime;
                if (enemyEyesight.PlayerTimeBeingSpotted > _settings.TimeForZombieToNoticePlayer)
                {
                    enemyEyesight.PlayerSpottedPosition           = playerPhysical.Position;
                    enemyEyesight.FakeSpotTimeAfterVisibilityLost = _settings.FakeVisionTime;
                }
            }
            else if (enemyEyesight.FakeSpotTimeAfterVisibilityLost > 0)
            {
                enemyEyesight.FakeSpotTimeAfterVisibilityLost -= Time.deltaTime;
                enemyEyesight.PlayerSpottedPosition            = playerPhysical.Position;
                enemyEyesight.PlayerTimeBeingSpotted           = _settings.TimeForZombieToNoticePlayer;
            }
            else
            {
                enemyEyesight.PlayerTimeBeingSpotted = 0;
            }
        }
    }
Ejemplo n.º 2
0
    public virtual void OnStateEnter()
    {
        var agent = _entityContainer.GetEntity <INavMeshAgent>();

        agent.MovementSpeed = _data.MovementSpeed;
        var noise = _entityContainer.GetEntity <NoiseProducerEntity>();

        _noiseLevelAtEnter = noise.NoiseLevel;
    }
Ejemplo n.º 3
0
    void CheckHearing(IEntityContainer listeningOne, IEntityContainer noiseMakingOne)
    {
        var hearing             = listeningOne.GetEntity <HearingEntity>();
        var hearingPhysical     = listeningOne.GetEntity <IPhysicalEntity>();
        var noiseMakingPhysical = noiseMakingOne.GetEntity <IPhysicalEntity>();
        var noise = noiseMakingOne.GetEntity <NoiseProducerEntity>();

        var   diff        = hearingPhysical.Position - noiseMakingPhysical.Position;
        float distance    = diff.magnitude;
        float diminuation = distance * hearing.NoiseDistanceDiminution;

        if (noise.NoiseLevel - diminuation > 0)
        {
            hearing.NoiseEntities.Add(noiseMakingOne);
        }
    }
Ejemplo n.º 4
0
    public static IEnumerator Do(IEntityContainer entityContainer, Vector3 destination)
    {
        var agent = entityContainer.GetEntity <INavMeshAgent>();

        agent.SetDestination(destination);
        yield return(null);

        while (!agent.IsDestinationReached())
        {
            yield return(null);
        }
    }
Ejemplo n.º 5
0
    public void Update()
    {
        _player.GetEntity <HearingEntity>()
        .NoiseEntities.Clear();
        foreach (var enemy in _enemies)
        {
            var enemyHearing = enemy.GetEntity <HearingEntity>();
            enemyHearing.NoiseEntities.Clear();

            CheckHearing(enemy, _player);
            CheckHearing(_player, enemy);

            var enemyNoise = enemy.GetEntity <NoiseProducerEntity>();
            if (enemyNoise.Type == NoiseType.ClickerScream)
            {
                foreach (var otherEnemy in _enemies.Where(e => e != enemy))
                {
                    CheckHearing(otherEnemy, enemy);
                }
            }
        }
    }