Resume() приватный Метод

private Resume ( ) : void
Результат void
Пример #1
0
        /// <summary>
        /// Allow pathfinding to resume.
        /// </summary>
        public override void OnStart()
        {
            navMeshAgent.speed        = speed.Value;
            navMeshAgent.angularSpeed = angularSpeed.Value;
#if UNITY_5_1 || UNITY_5_2 || UNITY_5_3 || UNITY_5_4 || UNITY_5_5
            navMeshAgent.Resume();
#else
            navMeshAgent.isStopped = false;
#endif

            SetDestination(Target());
        }
Пример #2
0
 void resume()
 {
     if (agent)
     {
         agent.Resume();
     }
 }
Пример #3
0
    void Update()
    {
        navMesh.destination = Player.transform.position;


        float Distance = Vector3.Distance(Player.transform.position, transform.position);

        if (Distance <= 6.0f)
        {
            navMesh.Stop();

            if (isAttack == false)
            {
                ani.SetBool("Idle", true);

                StartCoroutine(Attack());
            }
        }


        else
        {
            ani.SetBool("Idle", false);

            navMesh.Resume();
        }
    }
Пример #4
0
    public IEnumerator AIPatrol()
    {
        while (CurrentState == ENEMY_STATE.PATROL)
        {
            theLightSight.sensitivity = LineSight.SightSensitivity.STRICT;
            theAgent.Resume();
            theAgent.SetDestination(destination.position);

            while (theAgent.pathPending)
            {
                yield return(null);
            }

            if (theLightSight.canSeeTarget)
            {
                theAgent.Stop();
                CurrentState = ENEMY_STATE.CHASE;
                yield break;
            }

            yield return(null);
        }
    }
Пример #5
0
 void goToCover_Enter()
 {
     if (inCover == false)
     {
         nav.Resume();
         anim.SetBool("Crouch", false);
         anim.SetBool("Run", true);
         if (node != null)
         {
             nav.SetDestination(node.transform.position);
         }
     }
     else
     {
     }
 }
Пример #6
0
    // Use this for initialization
    void Start()
    {
        //Get references to components
        _navMeshAgent = GetComponent <UnityEngine.AI.NavMeshAgent>();
        _player       = GameObject.FindObjectOfType <Player>().gameObject;
        GameMngr      = GameObject.FindObjectOfType <GameManager>();

        // Set destination for navigation
        _navMeshAgent.SetDestination(_player.transform.position + Vector3.forward * _distanceToPlayer);
        _navMeshAgent.speed = Speed;

        //Start navigating
        _navMeshAgent.Resume();

        GetNextPosition();
    }
Пример #7
0
    void Update()
    {
        float distance = Vector3.Distance(enemyTransform.transform.position, player.transform.position);       //敌人与玩家的距离

        //如果敌人血量大于0
        if (eh.realHealth > 0)
        {
            //距离大于7,执行巡逻并自动寻路
            if (distance > 7f)
            {
                Patrol();
                enemy.Resume();                 //继续寻路
            }
            else
            {
                enemy.Stop();                 //停止寻路
                //距离大于2.5小于7,开始追逐
                if (distance > 2.5f)
                {
                    Chase();
                }
                else
                {
                    //距离小于2.5,开始攻击
                    Attack();
                }
                transform.LookAt(player);                //始终朝向主角
            }
        }
        //如果敌人死亡,停止一切活动,碰撞胶囊关闭
        if (eh.realHealth <= 0)
        {
            enemy.Stop();
            col.enabled = false;
        }
        //如果玩家死亡,敌人执行胜利动画,这里胜利动画只设定成了站立
        if (ph.realHealth <= 0)
        {
            EnemyVictory();
        }
        //如果敌人执行了胜利动画,敌人不再执行胜利动画
        if (victory == true)
        {
            EnemyIsVictory();
        }
    }
Пример #8
0
    void Update()
    {
        // Choose the next destination point when the agent gets
        // close to the current one.
        if (rdh != null)
        {
            if (rdh.ragdolled)
            {
                //Debug.Log("Ragdolled");
                //agent.Stop();
                agent.enabled      = false;
                rb.velocity        = Vector3.zero;
                rb.angularVelocity = Vector3.zero;
                return;
            }
        }
        if (!agent.enabled)
        {
            agent.enabled = true;
            agent.Resume();
        }
        if (agent.remainingDistance < remainingDistance)
        {
            GotoNextPoint();
        }



        // Update animation parameters
        if (!finished)
        {
            anim.SetBool("move", true);
            //anim.SetFloat("velx", );
            anim.SetFloat("velx", rb.velocity.magnitude);
            anim.SetFloat("vely", rb.angularVelocity.magnitude);
        }
        else
        {
            anim.SetBool("move", false);
        }

        //anim.SetFloat("vely", agent.velocity.y);

        //GetComponent<LookAt>().lookAtTargetPosition = agent.steeringTarget + transform.forward;
    }
Пример #9
0
    void Update()
    {
        //set up raycast to get position of mouse clicks in world
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Input.GetButtonDown("Fire2"))
        {
            if (Physics.Raycast(ray, out hit, 100))
            {
                //raycast and set the destination to hit location in world
                agent.destination = hit.point;
                agent.Resume();
                //also move the movement indicator to destination
                indicator.transform.position = hit.point;
            }
        }
    }
Пример #10
0
        /// <summary>Initialization Method of MoveToRandomPosition.</summary>
        /// <remarks>Check if there is a NavMeshAgent to assign it one by default and assign it
        /// to the NavMeshAgent the destination a random position calculated with <see cref="getRandomPosition()"/> </remarks>
        public override void OnStart()
        {
            navAgent         = gameObject.GetComponent <UnityEngine.AI.NavMeshAgent>();
            previousPosition = navAgent.transform.position;
            if (navAgent == null)
            {
                Debug.LogWarning("The " + gameObject.name + " game object does not have a Nav Mesh Agent component to navigate. One with default values has been added", gameObject);
                navAgent = gameObject.AddComponent <UnityEngine.AI.NavMeshAgent>();
            }
            getRandomPosition();
            navAgent.velocity = Vector3.zero;

            #if UNITY_5_6_OR_NEWER
            navAgent.isStopped = false;
            #else
            navAgent.Resume();
            #endif
        }
Пример #11
0
 // Update is called once per frame
 void Update()
 {
     if (!Manager.Instance.isPaused && !enemyHealth.isDead && !Manager.Instance.gameOver)
     {
         //if player is in range or this enemy has been attacked, track player
         if (enemyAttack.playerInRange || enemyHealth.currentHealth < (enemyHealth.startingHealth * Manager.Instance.difficultyMult))
         {
             nav.destination = player.position;
         }
         else
         {
             nav.destination = target.position; // track stone
         }
         nav.Resume();
         updateAnimatorCoordinates();
     }
     else if (nav.isActiveAndEnabled)
     {
         nav.Stop();
     }
 }
Пример #12
0
    IEnumerator MonsterAction()
    {
        while (!isDie)
        {
            switch (monsterState)
            {
            case MonsterState.idle:
                nvAgent.Stop();
                animator.SetBool("isTrace", false);
                break;

            case MonsterState.trace:
                nvAgent.destination = PlayerTr.position;
                nvAgent.Resume();
                //animator.SetBool("IsAttack", false);
                animator.SetBool("isTrace", true);
                break;
            }

            yield return(null);
        }
    }
Пример #13
0
    /*The enemy approaches towards the player
     * When close enough, face towards the player and attack */
    void ApproachAndAttack()
    {
        Vector3 ctargetposition   = currenttarget.transform.position; //current target position
        float   remainingdistance = Mathf.Abs(Vector3.Distance(ctargetposition, transform.position));

        //Above variable: Unity Logic is absolutely nonsense, so making own distance calculator.
        if (remainingdistance <= agent.stoppingDistance)
        {
            agent.Stop();                   // stop going toward the player, since already close enough
            float      rotationspeed = 10f; // how quickly this enemy rorates.
            Vector3    direction     = ctargetposition - transform.position;
            Quaternion rotation      = Quaternion.LookRotation(direction);
            transform.rotation = Quaternion.Lerp(transform.rotation, rotation, rotationspeed * Time.deltaTime);
            //slowly transition from current rotation to the target rotation.
            isAttacking = true; // play attack animation
        }
        else
        {
            isAttacking = false; // do not play attack animation
            agent.Resume();      // keep following the player.
        }
    }
Пример #14
0
    //몬스터의 상태값에 따라 적절한 동작을 수행하는 함수
    IEnumerator MonsterAction()
    {
        while (!isDie)
        {
            switch (monsterState)
            {
            //idle 상태
            case MonsterState.idle:
                //추적 중지
                nvAgent.Stop();
                //Animator의 IsTrace 변수를 false로 설정
                animator.SetBool("IsTrace", false);
                break;

            //추적 상태
            case MonsterState.trace:
                //추적 대상의 위치를 넘겨줌
                nvAgent.destination = playerTr.position;
                //추적을 재시작
                nvAgent.Resume();

                //Animator의 IsAttack 변수를 false로 설정
                animator.SetBool("IsAttack", false);
                //Animator의 IsTrace 변수값을 true로 설정
                animator.SetBool("IsTrace", true);
                break;

            //공격 상태
            case MonsterState.attack:
                //추적 중지
                nvAgent.Stop();
                //IsAttack을 true로 설정해 attack State로 전이
                animator.SetBool("IsAttack", true);
                break;
            }
            yield return(null);
        }
    }
Пример #15
0
    void Update()
    {
        if (started)
        {
            return;
        }

        if (target != null && !CloseEnough)
        {
            PlayWalk();
            agent.updateRotation = true;
            agent.Resume();
            agent.SetDestination(target.transform.position);
        }
        else if (CloseEnough)
        {
            PLayRest();
            agent.updateRotation = false;
            agent.Stop();
            FaceOpponent();
        }

        if (health <= 0 && !started)
        {
            agent.Stop();
            started       = true;
            agent.enabled = false;
            StartCoroutine(DeathRoutine());
        }

        if (!started && health != lastHealth)
        {
            Hit();
        }

        lastHealth = health;
    }
Пример #16
0
    public IEnumerator rotateToTarget(Vector3 point)
    {
        _isRotating = true;
        navMeshAgent.updateRotation = false;
        Quaternion lookDirection = Quaternion.LookRotation((point - this.transform.position).normalized);

        Quaternion.Euler(new Vector3(0, transform.eulerAngles.y, 0));

        int   loops         = 0;
        float rotationSpeed = 1000.0f;

        while (true)
        {
            if (!_isAlive | point != _currentMoveTarget)
            {
                yield break;
            }

            if (Quaternion.Angle(lookDirection, transform.rotation) < 30f | loops++ > 100)
            {
                anim.SetBool("startWalking", true);
                walking     = true;
                _isRotating = false;
                navMeshAgent.destination    = point;
                navMeshAgent.updateRotation = true;
                navMeshAgent.Resume();

                yield break;
            }

            this.gameObject.transform.rotation = Quaternion.RotateTowards(transform.rotation, lookDirection, rotationSpeed * Time.deltaTime);
            transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);

            yield return(null);
        }
    }
Пример #17
0
    // Update is called once per frame
    void Update()
    {
        if (isPatroling)
        {
            if (agent.remainingDistance == 0)
            {
                if (i >= Waypoints.Count - 1)
                {
                    i = 0;
                }
                isMoving = false;
                Debug.Log(Waypoints [i].name);
                agent.SetDestination(Waypoints [i].transform.position);
                i++;
            }

            if (!isMoving)
            {
                agent.Resume();

                isMoving = true;
            }
        }
    }
Пример #18
0
 /// <summary>
 /// 追捕
 /// </summary>
 void Chasing()
 {
     // 恢复导航功能
     nav.Resume();
     //把外面赋值的速度给导航速度
     nav.speed = chasingSpeed;
     nav.SetDestination(enemySight.personalAlarmPosition);
     // 距离人0.5米的距离时停止 开始射击
     if (nav.remainingDistance - nav.stoppingDistance < 0.5f)
     {
         // 追捕时间开始计时
         chasingTimer += Time.deltaTime;
         if (chasingTimer > chasingWaitTime)
         {
             chasingTimer = 0;
             print("重置位置");
             lastPlayerSighting.alarmPosition = lastPlayerSighting.normalPosition;
         }
     }
     else
     {
         chasingTimer = 0;
     }
 }
Пример #19
0
    // Update is called once per frame
    void Update()
    {
        if (playerHealth.currentHealth > 0)
        {
            if (destinationInRange == false)
            {
                if (stop == false)
                {
                    int random = Random.Range(0, 480);
                    duration = Random.Range(48, 120);
                    if (random > 478)
                    {
                        stop = true;
                        anim.SetFloat("Speed_f", 0);
                        if (Random.Range(0, 3) == 0)
                        {
                            anim.SetBool("Checktime_b", true);
                        }
                        else
                        {
                            anim.SetBool("Waving_b", true);
                        }
                        nav.Stop();
                    }
                    else
                    {
                        timer = 0;
                        stop  = false;
                        anim.SetFloat("Speed_f", speed);
                        anim.SetBool("Checktime_b", false);
                        anim.SetBool("Waving_b", false);

                        nav.Resume();
                    }
                }
                else if (stop == true && timer > duration)
                {
                    duration = 0;
                    timer    = 0;
                    stop     = false;
                    anim.SetFloat("Speed_f", speed);
                    anim.SetBool("Checktime_b", false);
                    anim.SetBool("Waving_b", false);
                    nav.Resume();
                }
                else
                {
                    timer = timer + 1;
                    //anim.SetFloat ("Speed_f", speed);
                }
            }
            else
            {
                anim.SetFloat("Speed_f", 0);
                DestroyImmediate(gameObject);
            }
        }
        else
        {
            nav.Stop();
            anim.SetBool("SexyDance_b", true);
        }
    }
Пример #20
0
 public void SendToTarget()
 {
     agent.SetDestination(target);
     agent.Resume();
     isActive = true;
 }
Пример #21
0
 void Seach_Enter()
 {
     agent.Resume();
     SetDestination(Target());
 }
Пример #22
0
 public void UpdateDestination(Vector3 position, bool isAnObject = false)
 {
     navMeshAgent.destination = position;
     destinationIsObject      = isAnObject;
     navMeshAgent.Resume();
 }
Пример #23
0
    ///////////////////////////////////////////////////////// STATE: IDLE STATIC


    void StateInit_IdleStatic()
    {
        navMeshAgent.SetDestination(startingPos);
        navMeshAgent.Resume();
    }
Пример #24
0
 public void resume_moving()
 {
     navagent.Resume();
 }
 void UpdateChasePath()
 {
     m_navMeshAgent.destination = m_character.transform.position;
     m_navMeshAgent.Resume();
 }
Пример #26
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.F))
        {
            Freeze();
        }
        if (isFrozen)
        {
            freezeTimer += Time.deltaTime;
            if (freezeTimer > 5)
            {
                agent.Resume();
                agent.velocity = preFrozenVel;
                // rb.constraints = RigidbodyConstraints.None;
                freezeTimer = 0;
                isFrozen    = false;
            }
            else
            {
                return;
            }
        }

        if (CheckForPlayer() || ListenForPlayer())
        {
            currState = AIState.Chase;
            timer     = 0;         //used to check time since player was last spotted, along with time since chase stopped (no need to have two timers)
        }
        else
        {
            timer += Time.deltaTime;
        }

        switch (currState)
        {
        case AIState.Patrol:
            if (agent.remainingDistance < 0.5f && !agent.pathPending)
            {
                setNextWaypoint();
            }
            break;

        case AIState.Chase:
            agent.SetDestination(GameObject.Find("Player").transform.position);                     //change "Player" name as appropriate
            if (agent.remainingDistance < 1f && !agent.pathPending)
            {
                //TODO: attack
                print("there will eventually have been an attack here");
            }
            if (timer >= 1)
            {
                currState = AIState.LoseTarget;
                timer     = 0;
            }
            break;

        case AIState.LoseTarget:
            agent.Stop();
            agent.ResetPath();
            //TODO: loop through confused animation
            if (timer >= 3)
            {
                currState = AIState.WalkBack;
            }
            break;

        case AIState.WalkBack:
            agent.Stop();
            agent.ResetPath();
            //walks to the nearest waypoint and continues the path
            float closestDist = Mathf.Infinity;
            float currDist;
            int   closestWaypoint = -2;
            for (int i = 0; i < waypoints.Length; i++)
            {
                currDist = Vector3.Distance(transform.position, waypoints[i].transform.position);
                if (currDist < closestDist)
                {
                    closestDist     = currDist;
                    closestWaypoint = i - 1;
                }
            }
            setNextWaypoint();
            currState = AIState.Patrol;
            break;

        default:
            break;
        }
    }
Пример #27
0
    void Update()
    {
        float distance = Vector3.Distance(transform.position, target.position);

        if (distance < attackRange + 2f)
        {
            attacking = true;
        }
        else
        {
            attacking = false;
        }

        if (attackR > attackRate)
        {
            anim.SetBool("Attack", true);
            StartCoroutine("CloseAttack");

            attackR = 0;
        }
        else
        {
            anim.SetBool("Attack", false);
        }
        if (!attacking)
        {
            nav.Resume();
            nav.SetDestination(target.position);
        }
        else
        {
            //nav.Stop();
            Vector3 relativePosition = transform.InverseTransformDirection(nav.desiredVelocity);

            float hor  = relativePosition.z;
            float vert = relativePosition.x;

            anim.SetFloat("Horizontal", hor, 0.6f, Time.deltaTime);
            anim.SetFloat("Vertical", vert, 0.6f, Time.deltaTime);


            attackR += Time.deltaTime;

            if (attackR > attackRate)
            {
                anim.SetBool("Attack", true);
                StartCoroutine("CloseAttack");

                attackR = 0;
            }
        }
        // If the enemy and the player have health left...
        //if (enemyHealth.currentHealth > 0 && playerHealth.currentHealth > 0)
        //{
        // ... set the destination of the nav mesh agent to the player.
        nav.SetDestination(target.position);
        //}
        // Otherwise...
        //else
        //{
        // ... disable the nav mesh agent.
        //    nav.enabled = false;
        //}
    }
    public void Act()
    {
        agent.Resume();

        if (behaviour.state == BotBehaviourDeusVult.BotState.IDLE)
        {
            if (Input.GetMouseButtonDown(0))
            {
                Ray        r = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(r, out hit))
                {
                    agent.SetDestination(hit.point);
                }
            }

            if (Input.GetMouseButtonDown(1))
            {
                Ray        r = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(r, out hit))
                {
                    Vector3 dir = hit.point - transform.position;
                    bot.ShootInDirection(dir);
                }
            }
        }



        //DEFENSE BASE


        else if (behaviour.state == BotBehaviourDeusVult.BotState.DefenseProtectBase)
        {
            Vector3 target = Vector3.zero;

            if (team.team_ID == 1)
            {
                target = new Vector3(-32, 2.083333f, 7);
            }
            else
            {
                target = new Vector3(32, 2.083333f, -7);
            }
            //agent.SetDestination (team.team_base.position);

            if (transform.position == target)
            {
                destinationReached = true;
            }

            if (Vector3.Distance(transform.position, target) > 15)
            {
                destinationReached = false;
            }


            if (!destinationReached)
            {
                agent.SetDestination(target);
            }
            else if (Vector3.Angle(transform.forward, team.team_base.position - transform.position) > 10)
            {
                agent.Stop();

                float angle = Vector3.Angle(transform.forward, team.team_base.position - transform.position);

                bot_object.transform.Rotate(Vector3.up, -Mathf.Clamp(360 * Time.deltaTime, 0, angle));
            }
        }


        // CAMPING

        else if (behaviour.state == BotBehaviourDeusVult.BotState.DefensePlantATent)
        {
            Vector3 target = Vector3.zero;

            if (team.team_ID == 1)
            {
                target = new Vector3(18, 2.083333f, -21);
            }
            else
            {
                target = new Vector3(-18, 2.083333f, 21);
            }
            //agent.SetDestination (team.team_base.position);

            if (transform.position == target)
            {
                destinationReached = true;
            }

            if (Vector3.Distance(transform.position, target) > 12)
            {
                destinationReached = false;
            }



            Vector3 lookAtTarget = Vector3.zero;

            if (team.team_ID == 1)
            {
                lookAtTarget = new Vector3(12, 2.083333f, -13);
            }
            else
            {
                lookAtTarget = new Vector3(-12, 2.083333f, 13);
            }



            if (!destinationReached)
            {
                agent.SetDestination(target);
            }
            else if (Vector3.Angle(transform.forward, lookAtTarget - transform.position) > 10)
            {
                agent.Stop();

                float angle = Vector3.Angle(transform.forward, lookAtTarget - transform.position);

                bot_object.transform.Rotate(Vector3.up, Mathf.Clamp(360 * Time.deltaTime, 0, angle));
            }
        }



        //ATTACK FLAG


        else if (behaviour.state == BotBehaviourDeusVult.BotState.AttackGetFlag)
        {
            int agentsAttackingAlive = 0;

            foreach (BotBehaviourDeusVult ally in teamController.teamMates)
            {
                if (ally.state == BotBehaviourDeusVult.BotState.AttackGetFlag && !ally.bot.is_dead)
                {
                    agentsAttackingAlive++;
                }
            }

            if (agentsAttackingAlive < 3 && Vector3.Distance(transform.position, team.team_base.position) < Vector3.Distance(transform.position, team.enemy_base.position))
            {
                if (!teamController.theyStoleOurFlag)
                {
                    Vector3 posWait = Vector3.zero;

                    if (team.team_ID == 1)
                    {
                        posWait = posWait1;
                    }
                    else
                    {
                        posWait = posWait0;
                    }


                    agent.SetDestination(posWait);

                    if (Vector3.Distance(posWait, teamController.ourFlagLastKnownPosition) <= 15)
                    {
                        agent.SetDestination(teamController.ourFlagLastKnownPosition);
                    }

                    else if (Vector3.Distance(posWait, teamController.theirFlagLastKnownPosition) <= 15)
                    {
                        agent.SetDestination(teamController.theirFlagLastKnownPosition);
                    }


                    else if (Vector3.Distance(transform.position, posWait) < 4)
                    {
                        agent.Stop();
                        bot_object.transform.Rotate(Vector3.up, 170 * Time.deltaTime);
                    }
                }
                else
                {
                    agent.SetDestination(teamController.ourFlagLastKnownPosition);
                }
            }


            // Si le drapeau allié est perdu, par terre, visible par l'équipe (position sûre) et proche, va le chercher
            else if (!master.IsTeamFlagHome(team.team_ID) && teamController.weSeeOurFlag && master.GetFlagCarrierID((team.team_ID + 1) % 2) == -1 && Vector3.Distance(transform.position, teamController.ourFlagLastKnownPosition) < 15)
            {
                agent.SetDestination(teamController.ourFlagLastKnownPosition);
            }

            else
            {
                agent.SetDestination(teamController.theirFlagLastKnownPosition);
            }
        }



        // BRING BACK FLAG


        else if (behaviour.state == BotBehaviourDeusVult.BotState.AttackHelpFlagGetter)
        {
            if (master.IsTeamFlagHome(team.team_ID) || (!master.IsTeamFlagHome(team.team_ID) && master.GetFlagCarrierID((team.team_ID + 1) % 2) == -1 && Vector3.Distance(teamController.ourFlagLastKnownPosition, team.team_base.position) < 15) /*!teamController.theyStoleOurFlag*/)
            {
                if (Vector3.Distance(transform.position, teamController.flagCarrier.transform.position) < 15 && Vector3.Distance(transform.position, team.team_base.position) < Vector3.Distance(teamController.flagCarrier.transform.position, team.team_base.position) /*Vector3.Distance (transform.position, teamController.flagCarrier.transform.position) > 15 && Vector3.Distance (transform.position, teamController.flagCarrier.transform.position) < 30 && Vector3.Distance (team.team_base.position, teamController.flagCarrier.transform.position) > Vector3.Distance(transform.position, team.team_base.position)*/)
                {
                    agent.Stop();
                    transform.Rotate(Vector3.up, 180 * Time.deltaTime);
                }
                else if (Vector3.Distance(transform.position, teamController.flagCarrier.transform.position) >= 30)
                {
                    agent.SetDestination(teamController.flagCarrier.transform.position + (team.team_base.position - teamController.flagCarrier.transform.position).normalized * 5);
                }
                else
                {
                    agent.SetDestination(team.team_base.position);
                }
            }
            else
            {
                agent.SetDestination(teamController.ourFlagLastKnownPosition);
            }
        }



        else if (behaviour.state == BotBehaviourDeusVult.BotState.AttackBringFlagBack)
        {
            Vector3 helpersGlobalPos = Vector3.zero;
            int     count            = 0;

            foreach (BotBehaviourDeusVult ally in teamController.teamMates)
            {
                if (ally.state == BotBehaviourDeusVult.BotState.AttackHelpFlagGetter)
                {
                    if (!ally.bot.is_dead)
                    {
                        helpersGlobalPos += ally.transform.position;
                        count++;
                    }
                }
            }

            if (count > 0)
            {
                helpersGlobalPos /= count;
            }

            if (!teamController.theyStoleOurFlag)
            {
                if (Vector3.Distance(transform.position, team.team_base.position) > 20)
                {
                    if (count > 0 && Vector3.Distance(helpersGlobalPos, team.team_base.position) < Vector3.Distance(transform.position, team.team_base.position))
                    {
                        //agent.SetDestination (helpersGlobalPos - 7 * (helpersGlobalPos - transform.position).normalized);
                        agent.SetDestination((helpersGlobalPos + team.team_base.position) / 2);
                    }
                    else
                    {
                        agent.SetDestination(team.team_base.position);
                    }
                }
                else
                {
                    agent.SetDestination(team.team_base.position);
                }
            }
            else
            {
                agent.SetDestination(team.team_base.position);
            }
        }



        // SHOOT ON SIGHT


        //WORKING WELL

        /*if (bot.can_shoot && shooter == null) {
         *
         *      foreach (GameObject ennemy in teamController.ennemies) {
         *
         *              if (bot.CanSeeObject (ennemy)) {
         *                      shooter = StartCoroutine ("Shoot", ennemy);
         *                      break;
         *
         *              }
         *
         *      }
         *
         *
         * }*/


        // TESTING

        if (bot.can_shoot)
        {
            List <GameObject> targets = new List <GameObject> ();
            bool seeCarrier           = false;

            foreach (GameObject ennemy in teamController.ennemies)
            {
                if (bot.CanSeeObject(ennemy))
                {
                    targets.Add(ennemy);

                    if (teamController.theyStoleOurFlag && ennemy.GetComponent <Bot> ().ID == master.GetFlagCarrierID(team.team_ID))
                    {
                        seeCarrier = true;
                    }
                }
            }


            foreach (GameObject target in targets)
            {
                if (seeCarrier && target.GetComponent <Bot> ().ID == master.GetFlagCarrierID(team.team_ID))
                {
                    StartCoroutine("Shoot", target);
                }

                else if (!seeCarrier)
                {
                    StartCoroutine("Shoot", target);
                }
            }
        }



        // VA CHERCHER DRAPEAU SI PROCHE

        /*if (teamController.theyStoleOurFlag && master.GetFlagCarrierID((team.team_ID + 1) % 2) == -1 && Vector3.Distance (teamController.ourFlagLastKnownPosition, transform.position) <= 5) {
         *
         *      int otherClose = 0;
         *
         *      foreach (BotBehaviourDeusVult ally in teamController.teamMates) {
         *
         *              if (ally != behaviour && Vector3.Distance (teamController.ourFlagLastKnownPosition, ally.transform.position) <= 15)
         *                      otherClose++;
         *
         *      }
         *
         *      if (otherClose < 1)
         *              agent.SetDestination (teamController.ourFlagLastKnownPosition);
         *
         *
         *
         * }
         *
         *
         * else if (master.GetFlagCarrierID(team.team_ID) == -1 && Vector3.Distance (teamController.theirFlagLastKnownPosition, transform.position) <= 5) {
         *
         *      int otherClose = 0;
         *
         *      foreach (BotBehaviourDeusVult ally in teamController.teamMates) {
         *
         *              if (ally != behaviour && Vector3.Distance (teamController.theirFlagLastKnownPosition, ally.transform.position) <= 15)
         *                      otherClose++;
         *
         *      }
         *
         *
         *
         *      if (otherClose < 1)
         *              agent.SetDestination (teamController.theirFlagLastKnownPosition);
         *
         *
         *
         *
         *
         * } */
    }
Пример #29
0
 void OnTriggerExit(Collider other)
 {
     agent.Resume();
     //need to ensure it is playernear
     playerNear = false;
 }
Пример #30
0
    // Update is called once per frame
    void Update()
    {
        if (nav.remainingDistance == 0 && !winded)
        {
            winded = true;
            anim.Play("Armature|Winded", -1, 0f);
            windedTimer = timeForWind;
            nav.Stop();
            GenerateTarget();
            itemTimer = 0;
            panting.Play();
        }

        if (!winded)
        {
            if (itemTimer > timeForItem)
            {
                itemTimer = 0;
                //Spawn an item
                int rand = Random.Range(0, 11);
                dropItem.Play();

                if (rand == 10)
                {
                    Instantiate(hgh, new Vector3(transform.position.x, transform.position.y + 27.43f, transform.position.z), transform.rotation);
                }
                else if (rand % 2 == 0)
                {
                    Instantiate(pillow, transform.position, transform.rotation);
                }
                else
                {
                    Instantiate(cactus, transform.position, transform.rotation);
                }
            }
            else
            {
                itemTimer += Time.deltaTime;
            }
        }

        if (invincibility > 0)
        {
            invincibility -= Time.deltaTime;
        }
        else
        {
            invincibility = 0;
        }

        if (winded)
        {
            if (windedTimer > 0)
            {
                windedTimer -= Time.deltaTime;
            }
            else
            {
                //GenerateTarget();
                windedTimer = 0;
                winded      = false;
                anim.Play("Armature|BossRun", -1, 0f);
                nav.Resume();
            }
        }
    }