UnityEngine.AI.NavMeshAgent.SetDestination C# (CSharp) Method

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
        public bool SetDestination(Vector3 target)
        {
            return INTERNAL_CALL_SetDestination(this, ref target);
        }

Usage Example

Example #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;
            }
        }
    }
All Usage Examples Of UnityEngine.AI.NavMeshAgent::SetDestination