Пример #1
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();
                }
            }
        }
Пример #2
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();
                }
            }
        }