示例#1
0
    void Update()
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Input.GetButtonDown("Fire1"))
        {
            if (Physics.Raycast(ray, out hit, 100))
            {
                if (hit.collider.CompareTag("plane"))
                {
                    navMeshAgent.destination = hit.point;
                    navMeshAgent.Resume();
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            targetRotation *= Quaternion.AngleAxis(90, Vector3.up);
        }
        else if (Input.GetKeyDown(KeyCode.E))
        {
            targetRotation *= Quaternion.AngleAxis(-90, Vector3.up);
        }

        transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, 10 * smooth * Time.deltaTime);
    }
示例#2
0
    // Update is called once per frame
    protected void Update()
    {
        // Target
        if (target != null)
        {
            float distance = Vector3.Distance(transform.position, target.transform.position);

            // Walk To
            if (distance > attackRange)
            {
                navAgent.Resume();
                navAgent.destination = target.transform.position;
            }
            // Attack
            else
            {
                navAgent.Stop();
                target.GetComponent <HitPoint>().hp -= attack * Time.deltaTime;
            }
        }

        // Death
        if (gameObject.GetComponent <HitPoint>().hp <= 0)
        {
            Destroy(gameObject);
        }
    }
示例#3
0
    IEnumerator MonsterAction()
    {
        while (!isDie)
        {
            switch (state)
            {
            case State.IDLE:
                anim.SetBool("IsTrace", false);
                nvAgent.Stop();
                break;

            case State.TRACE:
                //Debug.Log("Trace !!!");
                anim.SetBool("IsTrace", true);
                anim.SetBool(attackIdx, false);
                nvAgent.SetDestination(playerTr.position);
                nvAgent.Resume();
                break;

            case State.ATTACK:
                anim.SetBool(attackIdx, true);
                nvAgent.Stop();
                break;

            case State.DIE:
                break;
            }

            yield return(new WaitForSeconds(0.5f));
        }
    }
    public virtual IEnumerator Move(Movement movement)
    {
        CurrentCommand = movement;
        agent.speed    = WalkingSpeed;
        switch (movement.Style)
        {
        case MovementStyle.Run:
            agent.speed *= 2;
            IsSneaking   = false;
            break;

        case MovementStyle.Walk:
            IsSneaking = false;
            break;

        case MovementStyle.Sneak:
            IsSneaking   = true;
            agent.speed *= 0.5f;
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }
        Vector3 destination = new Vector3(movement.xCoord, 0, movement.yCoord);

        destination.x = Mathf.Clamp(destination.x, -295, 295);
        destination.y = Mathf.Clamp(destination.y, -295, 295);
        agent.Resume();
        agent.destination = GameManager.Instance.LevelOrigin.position + destination;
        yield return(WaitWithProgress(GameManager.Instance.Config.WalkingWindowSize));

        agent.speed = 0;
        agent.Stop();
        CurrentCommand = null;
    }
示例#5
0
 void OnCollisionExit(Collision col)
 {
     if (col.collider.tag == "Player")
     {
         agent.Resume();
     }
 }
示例#6
0
    // Update is called once per frame
    void Update()
    {
        if (unitState != e_unitStates.moving && enemiesInRange.Count > 0)
        {
            if (enemiesInRange[0] != null)
            {
                print("attacking: " + enemiesInRange[0].name);
                timer -= Time.deltaTime;
                if (timer <= 0.0f)
                {
                    Attack(enemiesInRange[0].GetComponent <AgentMovement>());
                }
                //attack(enemiesInRange[0]);
            }
            else
            {
                enemiesInRange.RemoveAt(0);
            }
        }
        else if (agent.remainingDistance > destinationThreshold && (unitState == e_unitStates.moving || enemiesInRange.Count == 0))
        {
            agent.Resume();
        }

        if (unitState != e_unitStates.stationary && agent.remainingDistance <= destinationThreshold)
        {
            if (agent.remainingDistance == 0)
            {
                agent.Stop();
                unitState = e_unitStates.stationary;
            }
            else if (targetOccupied)
            {
                agent.Stop();
                unitState = e_unitStates.stationary;
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            if (Input.GetKey(KeyCode.LeftControl))
            {
                RaycastHit hit;

                if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100))
                {
                    moveCommand(hit.point, null, true);
                }
            }
            else
            {
                RaycastHit hit;

                if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100))
                {
                    moveCommand(hit.point);
                }
            }
        }
    }
示例#7
0
    IEnumerator WaitAndGo(StopCounts stopCount)
    {
        // stop bus
        navAgent.Stop();
        print(this.name + " loading " + stopCount.waiting.ToString() + " passengers at " + stopOrder[nextStopIdx - 1]);

        this.loading = stopCount.waiting;

        // start loading
        while (stopCount.waiting > 0)
        {
            stopCount.waiting--; // load passenger
            this.loading--;
            passengersBoarded++;
            yield return(new WaitForSeconds(1f));   //Wait

            // print(this.name + " passengers waiting: " + stopCount.waiting);
            AddReward(rwdPsxPickup);
        }

        // confirm all passengers picked up (by this or other bus)
        this.loading = 0;

        // start bus
        navAgent.Resume();
    }
示例#8
0
        // Update is called once per frame
        void Update()
        {
            if (_health.IsDead() || Player.transform == null)
            {
                return;
            }
            var target = Player.transform.position;

            _agent.SetDestination(target);

            // Handle jumps here?
            if (_agent.remainingDistance >= _agent.stoppingDistance && !_attacking)
            {
                _agent.Resume();
                _character.Move(_agent.desiredVelocity, false);
                _character.SetAttacking(false);
            }
            else
            {
                _agent.Stop();
                _character.Move(Vector3.zero, false);

                HandleAttack();
                UpdateRotation();
            }

            if (!GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsName("Base.Attacking"))
            {
                _attacking = false;
            }
        }
示例#9
0
    virtual protected bool AttackPoint(Vector3 point)
    {
        Unit closestFoe = ScanClosest(~m_faction, m_scanRange);

        if (closestFoe)
        {
            AttackUnit(closestFoe);
        }
        else
        {
            m_navMeshAgent.SetDestination(point);
            m_navMeshAgent.Resume();
        }

        return(DistanceTo(point) < GameManager.attackPointDistanceEpsilon);
    }
示例#10
0
    void Update()
    {
        float distanceToPlayer = Vector3.Distance(player.transform.position, this.transform.position); //CALCULATE THE DISTANCE BETWEEN THE OBJECTS, STORE DISTANCE IN "distanceToPlayer"

        if (distanceToPlayer < 15 && distanceToPlayer > 2)
        {
            navAgent.Resume();
            navAgent.SetDestination(player.transform.position); //SET THE AI DESTINATION TO THE PLAYER'S TRANSFORM
        }

        if (distanceToPlayer < 2.5)
        {
            navAgent.Stop();
            if (!coroutineRunning)
            {
                StartCoroutine("DealDamage"); //BEGIN OUR CO-ROUTINE TO DAMAGE THE PLAYER
            }
        }

        if (distanceToPlayer < 1.5)
        {
            if (Input.GetMouseButtonDown(0))
            {
                DamageEnemy();
            }
        }
    }
示例#11
0
 // Update is called once per frame
 void Update()
 {
     if (target != null)
     {
         // 캐릭터와의 거리가 가까우면 일정 시간마다 반딧불을 소환하며 오브젝트풀링으로 관리하고 target에게 안내한다.
         if ((character.transform.position - transform.position).sqrMagnitude < 200.0f)
         {
             spawnTime += Time.deltaTime;
             Vector3 destination = target.transform.position;
             destination.y = transform.position.y;
             navMeshAgent.SetDestination(destination);
             if (navMeshAgent.isStopped)
             {
                 navMeshAgent.Resume();
             }
             if (spawnTime > 0.3f)
             {
                 spawnTime = 0.0f;
                 ObjectPooling();
             }
         }
         // 캐릭터와의 거리가 멀면 멈춘다.
         else
         {
             navMeshAgent.Stop();
         }
     }
 }
示例#12
0
    // Update is called once per frame
    void Update()
    {
        if (mode == 0)
        {
            agent.Stop();
            this.transform.Find("guardModel").GetComponent <Animator>().SetBool("walking", false);
        }
        else
        {
            agent.Resume();
            this.transform.Find("guardModel").GetComponent <Animator>().SetBool("walking", true);

            if (mode == 1)
            {
                PatrolAction();
            }
            else if (mode == 2)
            {
                ChaseAction();
            }
            else if (mode == 3)
            {
                MoveAction();
            }
        }

        modeChange = false;
    }
示例#13
0
    void Update()
    {
        //Счетчик всего ботов и если он 0 то проигрыш
        if (ogurec != null)
        {
            //agent.Resume();
            agent.SetDestination(ogurec.position);
        }
        if (ogurec == null)
        {
            agent.Stop();
            ogurec = GameObject.FindGameObjectWithTag("Ogurec").GetComponent <Transform>();
            //Debug.Log("ID" + ogurec.GetInstanceID());
            agent.SetDestination(ogurec.position);
            agent.Resume();
        }



        //if ((transform.position - target.transform.position).magnitude < 1 && !stop)
        //{
        //    stop = true;
        //    target.GetComponent<Navigate>().enabled = false;

        //    //var win = FindObjectOfType<Continue>();
        //    //win.WinCondition();
        //}

        //Navigate.DebugDrawPath(agent.path.corners);
    }
示例#14
0
    IEnumerator Resume()
    {
        yield return(new WaitForSeconds(SecondsWaitTilResume));

        navAgent.SetDestination(myTransform.position);
        navAgent.Resume();
    }
示例#15
0
    // Update is called once per frame
    void Update()
    {
        if (miningTimerOn)
        {
            miningTimer += Time.deltaTime;
            if (miningTimer >= 5)
            {
                miningTimer   = 0;
                miningTimerOn = false;
                navAgent.Resume();
            }
        }

        /*if (searchingTimerOn)
         * {
         *  searchingTimer += Time.deltaTime;
         *  if(searchingTimer >=5)
         *  {
         *      searchingTimer = 0;
         *      searchingTimerOn = false;
         *      nav
         *  }
         * }
         */
    }
示例#16
0
 void Update()
 {
     if (col_target == true)
     {
         if (hp_Orc_Wolf <= 0)
         {
             timeDeath = timeDeath + Time.deltaTime;
             if (timeDeath >= 0.2f)
             {
                 Destroy(gameObject);
                 //Instantiate(hp_potion, tr.position, tr.rotation);
                 king.Troll = king.Troll - 1;
             }
             anim.SetFloat("death", 1f);
         }
         // Debug.Log(NavMeshAgent.Warp);
         if (Vector3.Distance(tr.position, target.transform.position) < 7f)
         {
             nav.Stop();
             attack = 1;
             anim.SetFloat("attack", 1f);
             anim.SetFloat("go", -1f);
         }
         else
         {
             nav.Resume();
             this.gameObject.GetComponent <NavMeshAgent>().destination = target.transform.position;
             anim.SetFloat("attack", -0.5f);
             anim.SetFloat("go", 1f);
             attack = 0;
         }
     }
 }
示例#17
0
    // Update is called once per frame
    void Update()
    {
        if (targetSet)
        {
            if (walled == null)
            {
                agent.Resume();
            }
            else
            {
                agent.Stop();
            }

            if (!agent.pathPending)
            {
                if (agent.remainingDistance <= agent.stoppingDistance)
                {
                    abilities.Use(0);

                    if (!agent.hasPath || agent.velocity.sqrMagnitude == 0f)
                    {
                        // Done
                    }
                }
            }
        }
        if (targets[targetIndex] != null)
        {
            SetTarget(targetIndex % (targets.Length - 1));
        }
    }
示例#18
0
 // Update is called once per frame
 void Update()
 {
     if (healthPoint <= 0)
     {
         AnimatorStateInfo asi = this.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0);
         if (asi.normalizedTime > 1f && asi.IsName("back_fall"))
         {
             Lean.LeanPool.Despawn(this.gameObject);
         }
     }
     if (agent.enabled && healthPoint > 0)
     {
         agent.destination = player.transform.position;
         if (Vector3.Distance(this.transform.position, player.transform.position) < 2.5f)
         {
             SwitchAttack(true);
             agent.Stop();
         }
         else
         {
             SwitchAttack(false);
             PlaySound(walkAC);
             agent.Resume();
         }
     }
 }
示例#19
0
    void MouseMovement()
    {
        RaycastHit clickPosition;
        Ray        ray;

        if (Input.GetMouseButton(0))
        {
            ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out clickPosition))
            {
                movePosition      = clickPosition.point;
                agent.destination = movePosition;
                agent.Resume();
            }
        }
        else if (Input.GetMouseButton(1))
        {
            ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out clickPosition))
            {
                Vector3 targetPos = new Vector3(clickPosition.point.x, transform.position.y, clickPosition.point.z);
                transform.LookAt(targetPos);
            }
            agent.Stop();
        }
    }
示例#20
0
    IEnumerator MonsterAction()
    {
        while (!isDie)
        {
            switch (monsterState)
            {
            case MonsterState.idle:
                nvAgent.Stop();
                //nvAgent.isStopped = true;
                animator.SetBool("IsTrace", false);
                break;

            case MonsterState.trace:
                nvAgent.destination = playerTr.position;
                nvAgent.Resume();
                //nvAgent.isStopped = true;

                animator.SetBool("IsAttack", false);
                animator.SetBool("IsTrace", true);
                break;

            case MonsterState.attack:
                //추적 중지
                nvAgent.Stop();
                //nvAgent.isStopped = true;
                animator.SetBool("IsAttack", true);
                break;
            }
            yield return(null);
        }
    }
示例#21
0
    void Update()
    {
        if (dead)
        {
            if (_lerpC)            // We need to make dane more transparent before it disappears, so as to not look weird.
            {
                this.GetComponent <MeshRenderer>().material.SetColor("_Color", Color.Lerp(this.GetComponent <MeshRenderer>().material.GetColor("_Color")
                                                                                          , _deadC,
                                                                                          Time.deltaTime));
            }
        }
        else
        {
            // This is just to check if player is within reasonable range. Otherwise dane is too lazy to follow.
            if (Vector3.Distance(player.transform.position, this.transform.position) < 20)
            {
                NavMeshPath path = new NavMeshPath();
                agent.CalculatePath(player.transform.position, path);

                if (path.status == NavMeshPathStatus.PathComplete)
                {
                    agent.SetDestination(player.transform.position);
                    agent.Resume();
                }
                else                   // If agent cannot find a complete path, no purpose in trying.
                {
                    agent.Stop();
                }
            }
            else
            {
                agent.Stop();
            }
        }
    }
示例#22
0
    public override void Act(GameObject player, GameObject npc)
    {
        NavMeshAgent agent = npc.GetComponent <NavMeshAgent>();

        if (agent.enabled && !agent.pathPending)
        {
            agent.updateRotation = true;
            agent.Resume();

            agent.SetDestination(player.transform.position);
        }

        // Animator settings
        float moveValue = (agent.desiredVelocity).magnitude / npc.GetComponent <BaseEnemy>().InitialMovementSpeed;

        //Debug.Log("Move Value: " + moveValue);
        if (animator != null)
        {
            if (!agent.pathPending)
            {
                animator.speed = moveValue * enemy.MovementAnimationSpeed;
                animator.SetFloat("MoveValue", moveValue);
            }
            else
            {
                animator.speed = 1f;
                animator.SetFloat("MoveValue", 1.0f);
            }
        }
    }
示例#23
0
    void chase()
    {
        agent.destination = player.transform.position;
#pragma warning disable CS0618 // Type or member is obsolete
        agent.Resume();
#pragma warning restore CS0618 // Type or member is obsolete
    }
示例#24
0
    /*
     *      void OnTriggerStay(Collider Coll)
     * {
     *      if ( (Coll.gameObject.tag == "lookpoint"))
     *      {
     *              isChase = false;
     *      }
     * }
     * void OnTriggerExit(Collider Coll)
     * {
     *      if (Coll.gameObject.tag == "lookpoint") {
     *      isChase = true;
     *      }
     * }*/


    // Update is called once per frame
    void Update()
    {
        if (Vector3.Distance(player.transform.position, specialEnemy2.transform.position) <= 100.0f)
        {
            isChase = true;
        }
        else
        {
            isChase = false;
        }

        if (Mathf.Abs(Vector3.Angle(player.transform.forward, specialEnemy2.transform.position - player.transform.position)) <= 35.0f)
        {
            isChase = false;
        }


        //Debug.Log (isChase);

        if (isChase)
        {
            Vector3 targetPos = player.transform.position;
            agent.Resume();
            agent.SetDestination(targetPos);
        }
        else
        {
            agent.Stop();
            //agent.SetDestination (player.transform.position);
        }
    }
示例#25
0
 public void MoveTo(Vector3 position)
 {
     myContrl.IsMove = true;
     agent.Resume();
     agent.speed = myContrl.SoldierInterface.MovementSpeed;
     agent.SetDestination(position);
 }
示例#26
0
 void OnTriggerExit(Collider collider)
 {
     _navAgent.Stop();
     isChasing = false;
     _navAgent.SetDestination(patrolPoints[currentPatrolPoint].position);
     _navAgent.Resume();
 }
示例#27
0
        private void AlertState()
        {
            if (!CanSeePlayer())
            {
                GetComponent <Animator>().SetBool("IsMoving", true);

                GetComponent <NavMeshAgent>().destination = _lastKnownLocation;

                if (Vector3.Distance(transform.position, _lastKnownLocation) < .1f)
                {
                    State = EnemyState.Searching;
                    GetComponent <Animator>().SetBool("IsMoving", false);
                }
            }
            else
            {
                if (Vector3.Distance(transform.position, _player.transform.position) < MinDistance)
                {
                    GetComponent <Animator>().SetBool("IsMoving", false);
                    GetComponent <Animator>().SetBool("IsAttacking", true);
                    _lastKnownLocation = _player.transform.position;
                    GetComponent <NavMeshAgent>().destination = transform.position;
                }
                else
                {
                    if (_navAgent.isOnOffMeshLink)
                    {
                        if (!_traversingLink)
                        {
                            _currLink       = _navAgent.currentOffMeshLinkData;
                            _traversingLink = true;
                        }

                        var tlerp  = .1f;
                        var newPos = Vector3.Lerp(_currLink.startPos, _currLink.endPos, tlerp);
                        newPos.y          += 2f * Mathf.Sin(Mathf.PI * tlerp);
                        transform.position = newPos;

                        if (_currLink.startPos == _currLink.endPos)
                        {
                            transform.position = _currLink.endPos;
                            _traversingLink    = false;
                            _navAgent.CompleteOffMeshLink();
                            _navAgent.Resume();
                        }
                    }
                    else
                    {
                        GetComponent <Animator>().SetBool("IsMoving", true);

                        _lastKnownLocation = _player.transform.position;
                        GetComponent <NavMeshAgent>().destination = _player.transform.position;

                        var targetRotation = Quaternion.LookRotation(_player.transform.position - transform.position);
                        transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, TurnSpeed * Time.deltaTime);
                    }
                }
            }
        }
示例#28
0
    // Update is called once per frame
    void Update()
    {
        if (Target == null)
        {
            //_targetDistance = 100f;
            Debug.Log("플레이어 타겟 찾기");

            GameObject[] Monsters = GameObject.FindGameObjectsWithTag(targetType);

            if (Monsters.Length <= 0)
            {
                Debug.Log("게임종료");
                _anim.PlayAnimation(CPlayerStat.State.Idle);
            }

            foreach (GameObject Monster in Monsters)
            {
                float dis = Vector3.Distance(transform.position, Monster.transform.position);

                if (_targetDistance > dis)
                {
                    Debug.Log("플레이어 찾음");
                    _targetDistance = dis;
                    Target          = Monster;
                }
            }
        }



        if (Target != null)
        {
            Vector3 targetPos = Target.transform.position - transform.position;
            transform.rotation = Quaternion.LookRotation(targetPos);
            float dis = Vector3.Distance(transform.position, Target.transform.position);
            if (dis < 1)
            {
                _attack.NormalAttack(Target);
                _navMeshAgent.Stop();
                return;
            }
            else
            {
                _anim.PlayAnimation(CPlayerStat.State.Move);
            }

            _navMeshAgent.SetDestination(Target.transform.position);
            _navMeshAgent.Resume();


            if (CGameManager.getInstance.PlayerState(gameObject, "Attack"))
            {
                return;
            }


            _anim.PlayAnimation(CPlayerStat.State.Move);
        }
    }
示例#29
0
    // Update is called once per frame
    void FixedUpdate()
    {
        //stop the NPC when player wins
        if (GameObject.FindGameObjectWithTag("player").GetComponent <Animator>().GetBool("Win"))
        {
            stop = true;
            nav.Stop();
        }


        //when attacked, start the timer.
        if (attack)
        {
            nav.Stop();                     //pause nav mesh agent
            stop  = true;                   //stop moving
            timer = timer - Time.deltaTime; //decreasing timer
            if (timer < 0)
            {
                nav.Resume();            //resume nav mesh agent
                timer  = 5f;             //reset timer
                stop   = false;          //reset
                attack = false;          //reset
                anim.SetBool("move", true);
            }
        }


        if (!stop)
        {
            move();            //auto-move
        }
        //array of rays to detect players in a certain range
        Ray[] rays = new Ray[10];
        for (int i = 0; i < 10; i++)
        {
            rays[i].origin    = rayorigin.position;
            rays[i].direction = Quaternion.AngleAxis(12 * (i - 5), transform.up) * transform.forward;
            //Debug.DrawRay (rays[i].origin, rays[i].direction,Color.red);

            RaycastHit hitInfo = new RaycastHit();

            if (Physics.Raycast(rays[i], out hitInfo, 50))
            {
                //print(hitInfo.collider.gameObject.tag);
                if (hitInfo.collider.CompareTag("player"))               //once detect player, start following
                {
                    startNav = true;
                }
            }
        }


        //start nav
        if (startNav && nav.enabled)
        {
            print("start naving");
            nav.SetDestination(player.position);
        }
    }
示例#30
0
    void Update()
    {
        timer += Time.deltaTime;

        /**
         *  Follows the player until it reaches melee range, then attack.
         */
        if (player)
        {
            if (isDead)
            {
                return;
            }
            else if (myHealth.currentHealth <= 0)
            {
                /**
                 *  Stop the navigation and toggle isDead.
                 */
                nav.Stop();
                isDead = true;
                return;
            }
            else if (attackEnd)
            {
                animator.SetBool("IsAttacking", false);
                timer     = 0f;
                attackEnd = false;
                return;
            }
            else if (IsAttacking())
            {
                return;
            }

            if (!targetInRange && !isGameOver)
            {
                nav.Resume();
                nav.SetDestination(player.position);
                animator.SetBool("IsWalking", true);
            }
            else if (targetInRange && !isGameOver)
            {
                nav.Stop();
                animator.SetBool("IsWalking", false);

                if (timer >= coolDown)
                {
                    Attack();
                }

                FacePlayer();
            }
            else
            {
                nav.Stop();
                animator.SetBool("IsWalking", false);
            }
        }
    }