Beispiel #1
0
        public void Update()
        {
            //Debug.Log(aiController.gameObject.name + ": ReturnState.Update()");

            aiController.UpdateTarget();

            if (aiController.MyTarget != null && aiController.AggroEnabled() == true)
            {
                aiController.ChangeState(new FollowState());
            }

            float distanceToLeashPosition = Vector3.Distance(aiController.MyLeashPosition, aiController.MyBaseCharacter.CharacterUnit.transform.position);

            //Debug.Log(aiController.gameObject.name + ": ReturnState: Distance from spawn point: " + distance.ToString());
            if (distanceToLeashPosition <= 1)
            {
                aiController.ChangeState(new IdleState());
            }
            else
            {
                float agentDestinationDrift = Vector3.Distance(aiController.MyLeashPosition, aiController.MyBaseCharacter.AnimatedUnit.MyAgent.destination);
                if (agentDestinationDrift >= aiController.MyBaseCharacter.AnimatedUnit.MyAgent.stoppingDistance + aiController.MyBaseCharacter.AnimatedUnit.MyCharacterMotor.MyNavMeshDistancePadding)
                {
                    //Debug.Log("ReturnState.Update(). agent destination is: " + aiController.MyBaseCharacter.MyAnimatedUnit.MyAgent.destination + "; resetting to: " + aiController.MyStartPosition);
                    this.aiController.SetDestination(aiController.MyLeashPosition);
                }
            }
        }
        public void Update()
        {
            //Debug.Log(aiController.gameObject.name + ": IdleState.Update()");
            aiController.UpdateTarget();

            // change into follow state if the player is close
            if (aiController.MyTarget != null && aiController.AggroEnabled() == true)
            {
                //Debug.Log(aiController.gameObject.name + ": IdleState.Update(): setting follow state");
                aiController.ChangeState(new FollowState());
                return;
            }
            TryToEnterPatrolState();
        }
Beispiel #3
0
        public void Update()
        {
            //Debug.Log(aiController.gameObject.name + ": PatrolState.Update() at location: " + aiController.transform.position);
            if (aiController.MyAiPatrol.enabled == false)
            {
                aiController.ChangeState(new IdleState());
                return;
            }

            aiController.UpdateTarget();

            if (aiController.MyTarget != null && aiController.AggroEnabled() == true)
            {
                aiController.MyLeashPosition = aiController.MyBaseCharacter.CharacterUnit.transform.position;
                aiController.ChangeState(new FollowState());
            }

            bool getNewDestination = false;

            if (currentDestination == Vector3.zero && coroutine == null)
            {
                getNewDestination = true;
            }
            else if (Vector3.Distance(aiController.MyBaseCharacter.CharacterUnit.transform.position, currentDestination) <= aiController.MyBaseCharacter.AnimatedUnit.MyAgent.stoppingDistance + aiController.MyBaseCharacter.AnimatedUnit.MyCharacterMotor.MyNavMeshDistancePadding)
            {
                //Debug.Log(aiController.gameObject.name + ".PatrolState.Update(): Destination Reached!");

                // destination reached
                if (aiController.MyAiPatrol.MyCurrentPatrol.PatrolComplete())
                {
                    if (aiController.MyAiPatrol.MyCurrentPatrol.MyDespawnOnCompletion)
                    {
                        if (aiController.MyBaseCharacter.CharacterUnit != null)
                        {
                            aiController.MyBaseCharacter.CharacterUnit.Despawn(0, false, true);
                        }
                    }
                    else
                    {
                        TrySavePersistentData();
                        aiController.ChangeState(new IdleState());
                        return;
                    }
                }
                else
                {
                    //Debug.Log(aiController.gameObject.name + ".PatrolState.Update(): Destination Reached and patrol not complete yet!");
                    getNewDestination = true;
                }
            }


            //pathstatus: " + animatedUnit.MyAgent.pathStatus
            if (aiController.MyBaseCharacter.AnimatedUnit.MyAgent.pathStatus == UnityEngine.AI.NavMeshPathStatus.PathInvalid)
            {
                // this message means things are working properly and the unit just prevented itself from getting stuck or stalling
                //Debug.Log(aiController.gameObject.name + ".PatrolState.Update(): DESTINATION WAS INVALID, GETTING NEW DESTINATION");
                getNewDestination = true;
            }

            if (aiController.MyBaseCharacter.AnimatedUnit.MyAgent.pathStatus == UnityEngine.AI.NavMeshPathStatus.PathPartial)
            {
                // this message means things are working properly and the unit just prevented itself from getting stuck or stalling
                //Debug.Log(aiController.gameObject.name + ".PatrolState.Update(): DESTINATION WAS PARTIAL, GETTING NEW DESTINATION");
                getNewDestination = true;
            }

            if (getNewDestination == true)
            {
                TrySavePersistentData();
                Vector3 tmpDestination = aiController.MyAiPatrol.MyCurrentPatrol.GetDestination(true);
                if (tmpDestination == Vector3.zero)
                {
                    //Debug.Log(aiController.gameObject.name + ".PatrolState.Update(): GOT ZERO DESTINATION, SKIPPING TO NEXT UPDATE");
                    return;
                }
                // destination is safe, set it
                currentDestination = tmpDestination;

                SetMovementSpeed();
                coroutine = (aiController as MonoBehaviour).StartCoroutine(PauseForNextDestination(currentDestination));
            }
        }