예제 #1
0
    public IEnumerator wander()
    {


        Vector3 newPos = RandomNavmeshLocation(wanderRadius); // gets random point on navmesh
        while (true)
        {
            NavMeshPath path = new NavMeshPath();
            navMeshAgent.CalculatePath(newPos, path);
            if (path.status != NavMeshPathStatus.PathComplete) // checks to make sure that a path can be calcultaed with given random point
            {
                Debug.Log("Invalid path");
                newPos = NavMeshUtils.RandomNavSphere(transform.position, wanderRadius, -1);
            }
            else
            {
                break;

            }
           
        }
        AICurrentTargetLocation = newPos;

        navMeshAgent.SetDestination(newPos);
        yield return new WaitUntil(() => Vector3.Distance(gameObject.transform.position, newPos) <= 0.25f);
        wanderCoroutine = null;

    }
예제 #2
0
    public void RandomTargetPos()
    {
        Vector3 targetPos = NavMeshUtils.RandomPointOnMap(NavMesh.AllAreas, _mapPivotReference.localScale.x,
                                                          _mapPivotReference.localScale.z, _mapPivotReference.localScale.magnitude,
                                                          _mapPivotReference.transform.position);

        _agent.SetDestination(targetPos);
    }
예제 #3
0
    void RefreshUI()
    {
        float pathDistance  = NavMeshUtils.GetAgentCurrentDestinationPathDistance(snapTarget.GetNavMeshAgent());
        float estimatedTime = pathDistance / snapTarget.GetMaxSpeed();

        if (pathDistance < 0)
        {
            pathDistance  = 0;
            estimatedTime = 0;
        }
        remainingDistanceText.text = "Distance left: " + pathDistance.ToString("f1");
        remainingTimeText.text     = "Estimated time left: " + estimatedTime.ToString("f1") + "s";
    }
예제 #4
0
    private void OnDrawGizmos()
    {
        Gizmos.color = Color.red;
        Gizmos.DrawLine(NavMeshUtils.Place(transform.position), NavMeshUtils.Place(transform.position) + transform.forward * Distance);

        Gizmos.color = Color.blue;
        Vector3[] points = NavMeshUtils.MovePosition(transform.position, transform.forward * Distance, Quality);
        if (points.Length >= 2)
        {
            for (int i = 1; i < points.Length; i++)
            {
                Gizmos.DrawSphere(points[i], 0.05f);
                Gizmos.DrawLine(points[i - 1], points[i]);
            }
        }
    }
예제 #5
0
    //Refresh path if target is an object (because some object can move)
    void DrawPath(Vector3[] corners)
    {
        if (currPath != null && currPath.corners.Length > 1)
        {
            lineRenderer.positionCount = corners.Length;
            lineRenderer.SetPositions(corners);

            int currCornerIndex = NavMeshUtils.GetCurrentPathCornerIndex(agent, corners);
            for (int i = 0; i < currCornerIndex; i++)
            {
                lineRenderer.SetPosition(i, transform.position);
            }
        }
        else
        {
            lineRenderer.positionCount = 0;
        }
    }
예제 #6
0
 public Vector3 GetRandomPointOnMap()
 {
     return(NavMeshUtils.RandomPointOnMap(NavMesh.AllAreas, _mapPivotReference.localScale.x, _mapPivotReference.localScale.z, _mapPivotReference.localScale.magnitude, _mapPivotReference.transform.position));
 }
예제 #7
0
 private float GetDistanceToTarget()
 {
     return(NavMeshUtils.CalculatePathLength(context.NavigationAgent.transform.position, GetTargetPosition()));
 }