SetDestination() public method

Sets or updates the destination thus triggering the calculation for a new path.

public SetDestination ( Vector3 target ) : bool
target Vector3 The target point to navigate to.
return bool
コード例 #1
0
    void Patrol()
    {
        agent.speed = patrolSpeed;
        if (Vector3.Distance(this.transform.position, waypoints[waypointInd].transform.position) >= 1)
        {
            Quaternion newRotation = Quaternion.LookRotation(waypoints[waypointInd].transform.position - this.transform.position);
            //newRotation.x = 0f;
            //newRotation.z = 0f;

            //this.transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * 5f);

            agent.SetDestination(waypoints[waypointInd].transform.position);
        }
        else if (Vector3.Distance(this.transform.position, waypoints[waypointInd].transform.position) <= 1)
        {
            // if we're close to the position we want to get to
            // then it is time to go the next position
            waypointInd += 1;

            if (waypointInd >= waypoints.Length)
            {
                waypointInd = 0;
            }
        }
    }
コード例 #2
0
    public void Flee(Vector3 position)
    {
//		Vector3 fleeDirection, newGoal;
        NavMeshPath path;

        if (Vector3.Distance(position, this.transform.position) < detectionRadius)
        {
            /*fleeDirection = (this.transform.position - position).normalized;
             * newGoal = this.transform.position + fleeDirection * fleeRadius;
             * path = new NavMeshPath ();
             * _agent.CalculatePath (newGoal, path);*/
            path = CalculatePath(position);
            if (path != null)             //path.status != NavMeshPathStatus.PathInvalid) {
            {
                Debug.Log("valid path");
                _agent.SetDestination(path.corners [path.corners.Length - 1]);
                if (_anim != null)
                {
                    _anim.SetTrigger("isRunning");
                }
                _agent.speed        = 10;
                _agent.angularSpeed = 500;
            }
            else
            {
                Debug.Log("invalid path");
            }
        }
    }
コード例 #3
0
    void PickGoalLocation()
    {
        lastGoal = agent.destination;
        GameObject goalPos = GameEnviroment.Singleton.GetRandomGoal();

        agent.SetDestination(goalPos.transform.position);
    }
コード例 #4
0
ファイル: PatrolScript.cs プロジェクト: myonT/Kagami
    // Update is called once per frame
    void Update()
    {
        timepo += Time.deltaTime;

        //ここのGoNectPointがPlayerとの距離が近づいた後も呼ばれてしまっている
        //ので①の中に入った後は呼ばれないような処理を追加すればいける
        if (timepo > 20.0f && disance == true)
        {
            GotoNextPoint();
            timepo = 0;
        }


        Vector3 Apos = player.transform.position;
        Vector3 Bpos = transform.position;
        float   dis  = Vector3.Distance(Apos, Bpos);

        if (dis <= 20.0f)
        {
            //①
            agent.SetDestination(target.position);
            disance = false;
        }
        else if (dis > 20.0f)
        {
            disance = true;
        }
    }
コード例 #5
0
 /// <summary>
 /// navAgent
 /// </summary>
 /// <param name="position"></param>
 /// <param name="stopDistance"></param>
 /// <param name="moveSpeed"></param>
 public void MoveToTarget(Vector3 position, float stopDistance, float moveSpeed)
 {
     //通过寻路组件实现
     navAgent.SetDestination(position);
     navAgent.stoppingDistance = stopDistance;
     navAgent.speed            = moveSpeed;
 }
コード例 #6
0
 public void Attack(int num)
 {
     if (num == 0)
     {
         bonusAttack = Random.Range(0, 2);
         agent.SetDestination(GameObject.FindGameObjectWithTag("Player").transform.position);
         transform.LookAt(GameObject.FindGameObjectWithTag("Player").transform);
         animator.SetTrigger("attack");
         attackCount++;
     }
     else if (num == 1)
     {
         bonusAttack = Random.Range(0, 2);
         agent.SetDestination(GameObject.FindGameObjectWithTag("Player").transform.position);
         transform.LookAt(GameObject.FindGameObjectWithTag("Player").transform);
         animator.SetTrigger("attack2");
         attackCount++;
     }
     else if (num == 1)
     {
         bonusAttack = Random.Range(0, 2);
         agent.SetDestination(GameObject.FindGameObjectWithTag("Player").transform.position);
         transform.LookAt(GameObject.FindGameObjectWithTag("Player").transform);
         animator.SetTrigger("attack3");
         attackCount++;
     }
 }
コード例 #7
0
    void statechange()
    {
        NMA.isStopped = false;

        if (nowstate == 0)//Cruise State
        {
            NMA.stoppingDistance = 0;
            anim.SetInteger("State", 1);
            NMA.speed = walkSpeed;
            NMA.SetDestination(waypoints[waypoints_index].position);
            CruisePosition();
        }
        else if (nowstate == 1)//Chasing State
        {
            NMA.destination = player.transform.position;
            NMA.speed       = runSpeed;
            anim.SetInteger("State", 2);
        }
        else if (nowstate == 2)//Attack State
        {
            NMA.stoppingDistance = AttackDistance;
            anim.SetInteger("State", 3);
            //Debug.DrawLine(transform.position,player.transform.position,Color.red);
        }
        else if (nowstate == 3)
        {
            NMA.stoppingDistance = RemoteAttackDistance - 1;
            anim.SetInteger("State", 4);
        }
        else if (nowstate == -1)
        {
            anim.SetInteger("State", 0);
            // transform.LookAt(new Vector3(0, -1, 0));
        }
    }
コード例 #8
0
 void goHome()
 {
     agent.SetDestination(Home.position);
     goingHome = true;
     atGrocery = false;
     atShop    = false;
 }
コード例 #9
0
    private void Update()
    {
        var otherPlayer = GameObject.FindGameObjectWithTag("OtherPlayer");

        if (_enemyHealth.CurrentHealth > 0 && _playerHealth.CurrentHealth > 0)
        {
            if (otherPlayer != null)
            {
                var toPlayer      = Vector3.Distance(_player.position, transform.position);
                var toOtherPlayer = Vector3.Distance(otherPlayer.transform.position, transform.position);
                if (toPlayer > toOtherPlayer)
                {
                    _nav.SetDestination(otherPlayer.transform.position);
                }
                else
                {
                    _nav.SetDestination(_player.position);
                }
            }
            else
            {
                _nav.SetDestination(_player.position);
            }
        }
        else
        {
            _nav.enabled = false;
        }
    }
コード例 #10
0
ファイル: AIControlCrowd.cs プロジェクト: jordyhenry/Unity_IA
 private void Update()
 {
     if (agent.remainingDistance < 1)
     {
         ResetAgent();
         agent.SetDestination(goalLocations[Random.Range(0, goalLocations.Length)].transform.position);
     }
 }
コード例 #11
0
ファイル: Bot.cs プロジェクト: SylvainTran/cart315-w2021
 public void Seek(Vector3 location)
 {
     if (!agent.isOnNavMesh)
     {
         return;
     }
     agent.SetDestination(location);
 }
コード例 #12
0
 private void WalkToTarget()
 {
     if (agent.remainingDistance < 2 || agent.pathStatus != NavMeshPathStatus.PathComplete)
     {
         agent.updateRotation = true;
         nextTarget           = RandomTarget();
         agent.SetDestination(nextTarget);
     }
 }
コード例 #13
0
 private void Following()
 {
     if (Vector3.Distance(transform.position, target_obj.transform.position) > 0.25f)
     {
         if (target_obj != null)
         {
             agent.SetDestination(target_obj.transform.position);
         }
     }
 }
コード例 #14
0
ファイル: AgentTest.cs プロジェクト: wmbeaver/Lidar-Simulator
 public void Freeze()
 {
     agent.SetDestination(transform.position);
     if (anime != null)
     {
         foreach (Animator a in anime)
         {
             a.enabled = false;
         }
     }
     frozen = true;
 }
コード例 #15
0
    //------------------------------------------
    public IEnumerator AIPatrol()
    {
        if (PlayerAudioControl.chaseMusicOn)
        {
            StartCoroutine(stopChaseMusic(chaseMusicTimeout));
        }

        float timeToWait = isAngry ? .1f : 1f;

        yield return(new WaitForSeconds(timeToWait));

        seeking         = false;
        ThisAgent.speed = patrolSpeed;

        //Loop while patrolling
        while (currentstate == ENEMY_STATE.PATROL)
        {
            //Set strict search
            m_ThisScrLineOfSight.Sensitivity = scr_LineOfSight.SightSensitivity.STRICT;

            //Chase to patrol position
            ThisAgent.isStopped = false;
            ThisAgent.SetDestination(PatrolDestination.position);

            //Wait until path is computed
            while (ThisAgent.pathPending)
            {
                yield return(null);
            }

            //If we can see the target then start chasing
            if (m_ThisScrLineOfSight.CanSeeTarget)
            {
                ThisAgent.isStopped = true;
                CurrentState        = ENEMY_STATE.CHASE;
                yield break;
            }

            //Have we arrived at dest, get new dest
            //  debug ->  if (Vector3.Distance(transform.position, PatrolDestination.position) <= ThisAgent.stoppingDistance*1.2f)
            if (Vector3.Distance(transform.position, PatrolDestination.position) <= ThisAgent.stoppingDistance)
            {
                ThisAgent.isStopped = true;

                //check if current destination is an active gate and set new destination based on that
                PatrolDestination = newDestination(PatrolDestination);
                isAngry           = false;
            }

            //Wait until next frame
            yield return(null);
        }
    }
コード例 #16
0
        private void Update()
        {
            if (currentAIMode == AIMode.Combat)
            {
                if (!agent.enabled)
                {
                    return;
                }
                if (agent.remainingDistance <= agent.stoppingDistance + 0.05f)
                {
                    animator.SetBool("IsShooting", true);
                    inCover = true;
                    //agent.ResetPath();
                    transform.LookAt(target);
                    if (Time.time > lastShotTime + timeBetweenShots && inCover)
                    {
                        //Shoot ();
                        lastShotTime = Time.time;
                    }
                }
                else
                {
                    animator.SetBool("IsShooting", false);
                }
            }
            else
            {
                if (animator.GetFloat("Speed") > 0 && agent.remainingDistance <= agent.stoppingDistance + 0.05f)
                {
                    if (marchingPath != null)
                    {
                        currentPathIndex++;
                        if (currentPathIndex < marchingPath.Length)
                        {
                            agent.SetDestination(marchingPath[currentPathIndex]);
                        }
                    }
                }
            }

            AllyControl[] targets = FindObjectsOfType <AllyControl>();
            targetsTransform.Clear();
            foreach (AllyControl ac in targets)
            {
                if (ac.Alive)
                {
                    targetsTransform.Add(ac.transform);
                }
            }

            targetsTransform.Add(player);
        }
コード例 #17
0
 // Active for Chase
 void Chase()
 {
     // When the enemy is chasing the player I simply wanna set the Enemy's destination to be whereever the player is.
     agent.SetDestination(player.transform.position);
     if (Vector3.Distance(transform.position, player.transform.position) > 5.5f)
     {
         brain.PushState(Idle, OnIdleEnter, OnIdleExit);
     }
     if (withinAttackRange)
     {
         brain.PushState(Attack, OnAttackEnter, null);
     }
 }
コード例 #18
0
    void Start()
    {
        nav = GetComponent <NavMeshAgent>();
        nav.Warp(this.transform.position);
        PlayerTower = GameObject.FindGameObjectWithTag("Player Tower");
        EnemyTower  = GameObject.FindGameObjectWithTag("Enemy Tower");

        if (Vector3.Distance(this.transform.position, PlayerTower.transform.position) < Vector3.Distance(this.transform.position, EnemyTower.transform.position))
        {
            targetTower = EnemyTower.transform.position;
            twr         = EnemyTower.GetComponent <TowerBehaviour>().tower;

            minion.minionType = Minion.MinionType.PLAYER;
        }
        else
        {
            targetTower       = PlayerTower.transform.position;
            twr               = PlayerTower.GetComponent <TowerBehaviour>().tower;
            minion.minionType = Minion.MinionType.ENEMY;
        }
        if (this.gameObject.transform.position.z < 0)
        {
            nav.SetDestination(GameObject.FindGameObjectWithTag("LeftBridge").transform.position);
        }
        else
        {
            nav.SetDestination(GameObject.FindGameObjectWithTag("RightBridge").transform.position);
        }

        switch (minion.minionType)
        {
        case Minion.MinionType.ENEMY:
        {
            var v = this.gameObject.GetComponentsInChildren <Renderer>().ToList();
            foreach (var renderer in v)
            {
                renderer.material = RedMaterial;
            }
            break;
        }

        case Minion.MinionType.PLAYER: {
            var v = this.gameObject.GetComponentsInChildren <Renderer>().ToList();
            foreach (var renderer in v)
            {
                renderer.material = BlueMaterial;
            }
            break;
        }
        }
    }
コード例 #19
0
ファイル: EnemeyController.cs プロジェクト: skrivanroman/SSBG
    private void Patroling()
    {
        float currDistance = Vector3.Distance(walkPoints[currWalkPoint], transform.position);

        if (currDistance < 2)
        {
            walkPointSet  = false;
            currWalkPoint = (currWalkPoint + 1) % walkPoints.Length;
        }
        if (!walkPointSet)
        {
            agent.SetDestination(walkPoints[currWalkPoint]);
        }
    }
コード例 #20
0
 private void setNextWaypoint()
 {
     if (currWaypoint >= waypoints.Length - 1)
     {
         currWaypoint = 0;
     }
     else
     {
         currWaypoint++;
     }
     if (waypoints.Length != 0)
     {
         navMeshAgent.SetDestination(waypoints[currWaypoint].transform.position);
     }
 }
コード例 #21
0
ファイル: Character.cs プロジェクト: Felina-Lain/MaraudersMap
    /// <summary>
    /// Walkings  around at random.
    /// </summary>
    void WalkingAroundRandom()
    {
        //for duration of timer
        timer -= Time.deltaTime;

        //when timer is over
        if (timer <= 0)
        {
            //new position to go to
            Vector3 newPos = RandomNavSphere(transform.position, wanderRadius, -1);
            agent.SetDestination(newPos);
            //new random timer
            timer = Random.Range(wanderTimerMin, wanderTimerMax);
        }
    }
コード例 #22
0
    void MoveAI()
    {
        int index = random.Next(1, 4);

        _navMeshAgentvMesh.SetDestination(waypointsPositions[index - 1]);
        characterAnimator.SetBool("AI", true);
    }
コード例 #23
0
ファイル: Unit.cs プロジェクト: AldenHiggins/SOTSK-AR
    public void setDestination(Vector3 newDestination)
    {
        // If our new destination is close enough to where we currently are don't do anything
        if (Vector3.Distance(transform.position, newDestination) <= 1.0f)
        {
            // Stop the navmesh agent
            agent.isStopped = true;
            // Stop running
            anim.SetBool("Running", false);
            return;
        }

        anim.SetBool("Running", true);

        // Set our target position
        targetPosition = newDestination;

        // Activate our nav mesh agent and start moving to our destination
        if (!agent.isActiveAndEnabled)
        {
            agent.enabled = true;
        }
        agent.isStopped = false;
        agent.SetDestination(newDestination);
    }
コード例 #24
0
    // Update is called once per frame
    void Update()
    {
        if (posicion.position.x == pointA[0] && posicion.position.z == pointA[2] && gotoB == false)
        {
            Debug.Log("entra");
            gotoB = true;
            nav.SetDestination(pointB);
        }

        if (posicion.position.x == pointB[0] && posicion.position.z == pointB[2] && gotoB == true)
        {
            Debug.Log("no deberia entrar");
            gotoB = false;
            nav.SetDestination(pointA);
        }
    }
コード例 #25
0
    void Wander()
    {
        var dist = Random.Range(WanderDistanceMin, WanderDistanceMax);

        Destination = tr.position + Random.insideUnitSphere * dist;
        navMeshAgent.SetDestination(Destination);
    }
コード例 #26
0
ファイル: CentaurManager.cs プロジェクト: GusOs/Fantasy
    public void checkAnimation()
    {
        if (Vector3.Distance(player.position, this.transform.position) < distance)
        {
            Vector3 direction = player.position - this.transform.position;
            direction.y = 0;

            this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(direction), 0.1f);

            anim.SetInteger("moving", 0);
            nav           = GetComponent <NavMeshAgent>();
            nav.isStopped = true;

            if (direction.magnitude < 15)
            {
                nav           = GetComponent <NavMeshAgent>();
                nav.isStopped = false;
                anim.SetBool("attack", false);
                anim.SetBool("trick", true);
                anim.SetInteger("moving", 1);
                nav.SetDestination(player.position);
            }

            if (direction.magnitude < 5)
            {
                nav           = GetComponent <NavMeshAgent>();
                nav.isStopped = true;
                anim.SetInteger("moving", 0);
                anim.SetBool("attack", true);
            }
        }
    }
コード例 #27
0
ファイル: HazMovement.cs プロジェクト: Engr1/Project
    void Update()
    {
        // Nav Mesh Stuff

        Move = GetComponent <UnityEngine.AI.NavMeshAgent>();
        Move.SetDestination(Player.transform.position);


        // Make Sure The Enemy Is Facing The Player

        transform.LookAt(Player);

        // Registering Player Score

        Total = ScoreCounter1.Coop + ScoreCounter2.Coop + ScoreCounter3.Coop +
                ScoreCounter4.Coop + ScoreCounter5.Coop;


        // Movement Speed Increasing Based On Player Score

        if (Total > 799)
        {
            Move.speed = .3f;
        }

        if (Total > 1399)
        {
            Move.speed = .6f;
        }

        if (Total > 1999)
        {
            Move.speed = 1.1f;
        }
    }
コード例 #28
0
    // Update is called once per frame
    public void StartSkyNet()
    {
        //while(failedStatus != true) {
        agent.speed = (float)speedAgent;
        finishPoint = prog.EndPT.transform.position;
        startPoint  = prog.StartPT.transform.position;
        //UnityEngine.Debug.Log("End pos:"+finishPoint);
        agent.Warp(startPoint);
        // IF true The AI failed
        if (!failedStatus)
        {
            if (GameObject.Find("NavMeshBaker").GetComponent <NavMeshBaker>().getNavBuilded())
            {
                // Init Start Time //
                if (flag)
                {
                    startTime = DateTime.Now;
                    //UnityEngine.Debug.Log(startTime);
                    flag = false;
                }

                // AI Movement //
                agent.SetDestination(finishPoint);
            }
        }
        else
        {
            // Set AI speed to 0 if failed
            agent.velocity = Vector3.zero;
        }
        //}
    }
コード例 #29
0
 // Update is called once per frame
 void Update()
 {
     if (transform.position.z > 20)
     {
         agent.SetDestination(destination.position);
     }
 }
コード例 #30
0
ファイル: EnemyController.cs プロジェクト: mrtsven/jumper
    // Update is called once per frame
    void Update()
    {
        // Distance to the target
        float distance = Vector3.Distance(target.position, transform.position);

        // If inside the lookRadius
        if (distance <= lookRadius)
        {
            // If within attacking distance
            if (distance <= agent.stoppingDistance)
            {
                // Attack the target
                FaceTarget();   // Make sure to face towards the target

                createInversionField();
            }
            else
            {
                // Move towards the target
                agent.SetDestination(target.position);
            }
        }

        CheckDeath();
    }