/// <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();
                    }
                }
            }
        }
 //Move to sound position if player not in vision
 private void Sensors_OnHearSound(SoundStimuli obj)
 {
     AISensors.VisionResult visionResult = entity.Sensors.CheckVision();
     if (!visionResult.playerVisible)
     {
         entity.Data.currentAttentionWaitTime = entity.Data.AttentionWaitTime;
         entity.Data.lastSeenPlayerPosition   = obj.caster.position;
     }
 }
Exemple #3
0
        ///<inheritdoc/>
        public override void Init(AIEntity entity)
        {
            base.Init(entity);

            weaponBehaviour = new AIWeaponBehaviour(entity);
            visionResult    = new AISensors.VisionResult();
            //set random cover time from cover and move to it
            done = false;
            time = Random.Range(currentCover.TimeInCover.x, currentCover.TimeInCover.y);
            controller?.ForceMoveTo(currentCover.transform.position);
        }
Exemple #4
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();
                }
            }
        }
Exemple #5
0
        private void CheckVision()
        {
            if (Player.Instance == null)
            {
                playerVisible = false;
                Invoke("CheckVision", playerVisible ? Time.fixedDeltaTime : updateRate);
                return;
            }

            AISensors.VisionResult visionResult = sensors.CheckVision();
            if (!playerVisible && visionResult.playerVisible)
            {
                timeout = alarmTime;
            }
            playerVisible = visionResult.playerVisible;
            Invoke("CheckVision", playerVisible ? Time.fixedDeltaTime : updateRate);
        }
Exemple #6
0
        ///<inheritdoc/>
        public override void Update()
        {
            base.Update();

            //move to cover
            if (!inCover)
            {
                //check if AI in cover yet
                if (Vector3.Distance(entity.transform.position, currentCover.transform.position) <= 1)
                {
                    inCover = true;
                }
            }
            else
            {
                //decreasing the timer
                time -= Time.deltaTime;
                //if we see player and timer is not done then shooting
                visionResult = entity.Sensors.CheckVision();
                controller?.RotateTo((entity.Data.lastSeenPlayerPosition - entity.transform.position).normalized);
                if (time > 0)
                {
                    //entity.data.currentAggresionWaitTime = entity.data.aggresionWaitTime;
                    if (Player.Instance && visionResult.playerVisible)
                    {
                        entity.Data.lastSeenPlayerPosition = Player.Instance.transform.position;
                        entity.assignedZone.PropogatePlayerPosition(entity.Data.lastSeenPlayerPosition);

                        weaponBehaviour.DoAction();
                    }
                }
                else
                {
                    End();
                }
            }
        }
Exemple #7
0
        ///<inheritdoc/>
        public override void Update()
        {
            //Check if player visible, and switch to attention state if so
            AISensors.VisionResult visionResult = entity.Sensors.CheckVision();
            if (visionResult.playerVisible)
            {
                if (entity.Data.currentPlayerSpotWaitTime > 0)
                {
                    entity.Data.currentPlayerSpotWaitTime -= Time.deltaTime;
                }
                else
                {
                    entity.Data.lastSeenPlayerPosition = Player.Instance.transform.position;
                    controller?.SwitchState(controller?.attentionState);
                    return;
                }
            }
            else
            {
                if (entity.Data.currentPlayerSpotWaitTime < entity.Data.PlayerSpotWaitTime)
                {
                    entity.Data.currentPlayerSpotWaitTime += Time.deltaTime;
                }
            }

            if (visionResult.attentionPoint != null)
            {
                entity.Attention();
                entity.assignedZone.PropogatePlayerPosition(visionResult.attentionPoint.position);
                visionResult.attentionPoint.gameObject.SetActive(false);
                return;
            }

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

            if (!entity.InFear)
            {
                //Patrol routine
                if (entity.Data.Path != null)
                {
                    //Select target point
                    patrolPath = entity.Data.Path;
                    if (targetPathNode == null)
                    {
                        targetPathNode = entity.Data.Path.Next(out AIPath newPath);
                        if (newPath != null)
                        {
                            entity.Data.Path = newPath;
                        }
                        if (targetPathNode != null)
                        {
                            entity.Data.pointWaitTime = targetPathNode.WaitTime;
                        }
                    }
                    else
                    {
                        //Movement to target point, stay and rotate towards point direction if wait time is > 0
                        controller?.MoveTo(targetPathNode.Pos);
                        if (Vector3.Distance(entity.transform.position, targetPathNode.Pos) < 0.75f)
                        {
                            entity.Data.pointWaitTime -= Time.deltaTime;
                            if (entity.Data.pointWaitTime > 0f)
                            {
                                controller?.RotateTo(targetPathNode.Dir);
                            }
                            else
                            {
                                targetPathNode = null;
                            }
                        }
                    }
                }
                else
                {
                    //Move to spawn point if no path
                    controller?.MoveTo(entity.Data.spawnPoint);
                    if (Vector3.Distance(entity.transform.position, entity.Data.spawnPoint) < 0.75f)
                    {
                        controller?.RotateTo(lastDir);
                    }
                }
            }

            //Sleep routine
            entity.Data.waitForSleep -= Time.deltaTime;
            if (entity.Data.waitForSleep <= 0f)
            {
                controller?.Sleep();
            }
        }