/// <inheritdoc/>
        public override void Update()
        {
            //CheckVision
            AISensors.VisionResult visionResult = entity.Sensors.CheckVision();

            if (visionResult.fearPoint != null)
            {
                AIUtils.InitiateFear(entity, visionResult.fearPoint);
            }

            if (entity.InFear)
            {
                entity.Data.fearTimer -= Time.deltaTime;
            }

            if (!entity.InFear)
            {
                if (visionResult.playerVisible)
                {
                    if (Vector3.Distance(entity.transform.position, Player.Instance.transform.position) <= 0.9f)
                    {
                        controller?.SpotPlayer();
                    }

                    //Move to last seen position
                    controller?.MoveTo(entity.Data.lastSeenPlayerPosition);

                    //Spot with outer vision and reset timers
                    if (visionResult.sensorType == AISensors.SensorType.Outer)
                    {
                        entity.Data.currentAttentionPlayerSpotWaitTime = entity.Data.AttentionPlayerSpotWaitTime;
                        entity.Data.currentAttentionWaitTime           = entity.Data.AttentionWaitTime;
                    }
                    //Spot with inner vision and switch to aggression if timer is up
                    else if (visionResult.sensorType == AISensors.SensorType.Inner)
                    {
                        entity.Data.currentAttentionPlayerSpotWaitTime -= Time.deltaTime;
                        if (entity.Data.currentAttentionPlayerSpotWaitTime <= 0)
                        {
                            controller?.SpotPlayer();
                        }
                    }
                    entity.Data.lastSeenPlayerPosition = Player.Instance.transform.position;
                }
                //Relax if player not seen
                else
                {
                    //Move to last seen position with rand position
                    controller?.MoveTo(entity.Data.lastSeenPlayerPosition + walkRand.randPos);
                    walkRand.DoAction();

                    entity.Data.currentAttentionPlayerSpotWaitTime = entity.Data.AttentionPlayerSpotWaitTime;
                    entity.Data.currentAttentionWaitTime          -= Time.deltaTime;
                    if (entity.Data.currentAttentionWaitTime <= 0)
                    {
                        controller?.Relax();
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <inheritdoc/>
        public override void Update()
        {
            base.Update();

            AISensors.VisionResult visionResult = entity.Sensors.CheckVision();
            if (visionResult.fearPoint != null)
            {
                AIUtils.InitiateFear(entity, visionResult.fearPoint);
            }

            if (entity.InFear)
            {
                entity.Data.fearTimer -= Time.deltaTime;
            }

            //Attack player if visible
            if (visionResult.playerVisible && Player.Instance != null)
            {
                entity.Data.currentAggresionWaitTime = entity.Data.AggresionWaitTime;
                try
                {
                    entity.Data.lastSeenPlayerPosition = Player.Instance.transform.position;
                }
                catch
                {
                }
                entity.assignedZone.PropogatePlayerPosition(entity.Data.lastSeenPlayerPosition);

                if (!entity.InFear)
                {
                    controller?.MoveTo(!weaponBehaviour.IsDistanceOptimal() ? entity.Data.lastSeenPlayerPosition : entity.transform.position, false);
                }

                weaponBehaviour.DoAction();
            }
            //else move to last seen position
            else
            {
                if (!entity.InFear)
                {
                    controller?.MoveTo(entity.Data.lastSeenPlayerPosition + walkRand.randPos);
                }

                walkRand.DoAction();

                entity.Data.currentAggresionWaitTime -= Time.deltaTime;
                if (entity.Data.currentAggresionWaitTime <= 0)
                {
                    controller?.Relax();
                }
            }
        }