Beispiel #1
0
        public bool SetTarget(Vector3 t)
        {
            if (enabled && NavMesh2D.GetNavMeshObject())
            {
                pathingTarget = NearestPoint(t, NavMesh2D.GetNavMeshObject().NavMesh);
                path          = NavMesh2D.GetSmoothedPath(transform.position, pathingTarget);

                if (path.Count <= 0)
                {
                    Vector3?cn = ClosestNode(t);

                    if (cn == null)
                    {
                        return(false);
                    }

                    pathingTarget = (Vector3)cn;

                    path = NavMesh2D.GetSmoothedPath(transform.position, pathingTarget);
                }

                Vector2 vk = Vector2.zero;
                for (int i = 0; i < path.Count; i++)
                {
                    vk = path[i];
                }

                if (path != null && path.Count > 0)
                {
                    velocity = lastVelBeforeZero;
                }
            }

            return(true);
        }
Beispiel #2
0
    private void BreakLink()
    {
        if (LinkEstablished)
        {
            NavMesh2D.GetNavMeshObject().GetNode(PointA).DisconnectFrom(PointB);
            NavMesh2D.GetNavMeshObject().GetNode(PointB).DisconnectFrom(PointA);
        }

        PointA = -1;
        PointB = -1;
    }
Beispiel #3
0
 private void EnforceConnection()
 {
     if (LinkEstablished && LinkActive)
     {
         NavMesh2D.GetNavMeshObject().GetNode(PointA).ConnectTo(PointB, NavMesh2DConnection.ConnectionType.Standard);
         if (Bidirectional)
         {
             NavMesh2D.GetNavMeshObject().GetNode(PointB).ConnectTo(PointA, NavMesh2DConnection.ConnectionType.Standard);
         }
     }
 }
Beispiel #4
0
    void OnDrawGizmos()
    {
        Gizmos.DrawWireSphere(transform.position, 0.05f);
        if (LinkEstablished == false || NavMesh2D.SceneHasNavmesh() == false)
        {
            return;
        }

        Gizmos.color = Color.white;
        GizmosExtra.GizmosDrawArrow(NavMesh2D.GetNavMeshObject().GetNode(PointA).position + Vector3.back * 0.1f, NavMesh2D.GetNavMeshObject().GetNode(PointB).position + Vector3.back * 0.1f, 0.2f);
        if (Bidirectional)
        {
            GizmosExtra.GizmosDrawArrow(NavMesh2D.GetNavMeshObject().GetNode(PointB).position + Vector3.back * 0.1f, NavMesh2D.GetNavMeshObject().GetNode(PointA).position + Vector3.back * 0.1f, 0.2f);
        }
    }
Beispiel #5
0
        Vector3?ClosestNode(Vector3 point)
        {
            var navmeshObject = NavMesh2D.GetNavMeshObject();

            if (navmeshObject == null)
            {
                return(null);
            }

            var node = navmeshObject.ActualClosestNodeTo(new Vector2(point.x, point.y), false);

            if (node == null)
            {
                return(null);
            }

            Vector3 n = node.position;

            return(n);
        }
Beispiel #6
0
    void EstablishLink()
    {
        _lastPointAPos     = transform.TransformPoint(PointAPos);
        _lastPointBPos     = transform.TransformPoint(PointBPos);
        _lastBidirectional = Bidirectional;

        PointA = NavMesh2D.GetNavMeshObject().ClosestNodeIndexTo(transform.TransformPoint(PointAPos));
        PointB = NavMesh2D.GetNavMeshObject().ClosestNodeIndexTo(transform.TransformPoint(PointBPos));

        if (PointA == -1 || PointB == -1)
        {
            PointA = NavMesh2D.GetNavMeshObject().ActualClosestNodeIndexTo(transform.TransformPoint(PointAPos));
            PointB = NavMesh2D.GetNavMeshObject().ActualClosestNodeIndexTo(transform.TransformPoint(PointBPos));
            if (PointA == -1 || PointB == -1)
            {
                return;
            }
        }

        if (Bidirectional && NavMesh2D.GetNavMeshObject().GetNode(PointA).ConnectedTo(PointB) && NavMesh2D.GetNavMeshObject().GetNode(PointB).ConnectedTo(PointA))
        {
            PointA = -1;
            PointB = -1;
            return;
        }

        if (!Bidirectional && NavMesh2D.GetNavMeshObject().GetNode(PointA).ConnectedTo(PointB))
        {
            PointA = -1;
            PointB = -1;
            return;
        }

        NavMesh2D.GetNavMeshObject().GetNode(PointA).ConnectTo(PointB, NavMesh2DConnection.ConnectionType.Standard);
        if (Bidirectional)
        {
            NavMesh2D.GetNavMeshObject().GetNode(PointB).ConnectTo(PointA, NavMesh2DConnection.ConnectionType.Standard);
        }
    }