Beispiel #1
0
        private void SetupNavVectorField()
        {
            float xCount = width / dist, yCount = height / dist, zCount = length / dist;

            for (int x = 0; x < xCount + 1; x++)
            {
                Vector3 right = startTransform.right * x * dist;
                for (int y = 0; y < yCount + 1; y++)
                {
                    Vector3 up = startTransform.up * y * dist;
                    for (int z = 0; z < zCount + 1; z++)
                    {
                        Vector3 forward = startTransform.forward * z * dist;

                        Vector3 dir = (right + up + forward);

                        VectorNode newNode = ScriptableObject.CreateInstance("VectorNavigation.VectorNode") as VectorNode;
                        newNode.postition = offset;
                        newNode.direction = dir;
                        startNodes.Add(newNode);
                        indexList.Add(newNode.GetRelativPosition());
                    }
                }
            }
        }
Beispiel #2
0
 private void SetNodeNeighbors()
 {
     foreach (VectorNode node in startNodes)
     {
         foreach (Vector3 dir in directions)
         {
             VectorNode neighborNode = GetNodeFromPosition(node.GetRelativPosition() + dir);
             if (neighborNode != null)
             {
                 node.neighbors.Add(neighborNode);
             }
         }
     }
 }
Beispiel #3
0
        public void Setup(VectorNode node, Vector3 start, Vector3 end, VectorPathNode preNode)
        {
            vecNode = node;

            position = node.GetRelativPosition();
            normal   = node.normal;

            if (preNode == null)
            {
                startDistance = Vector3.Distance(position, start);
            }
            else
            {
                startDistance = Vector3.Distance(position, preNode.position) + preNode.startDistance;

                lastNode = preNode;
                name     = preNode.name + 1;
                lastName = name - 1;
            }
            endDistance = Vector3.Distance(position, end);
        }
        private VectorNode GetClosestNode(Vector3 pos, bool?start = false)
        {
            VectorNode        result = null;
            List <VectorNode> nodes  = possibleNodes;

            if (start.Value)
            {
                nodes = navField.activeNodes;
            }

            //Using LinQ to find closest node based on distance in current NavigationField:
            result = navField.activeNodes.Select(select => new
            {
                Value      = select,
                Difference = (pos - select.GetRelativPosition()).magnitude
            }
                                                 ).OrderBy(select => select.Difference).First().Value;



            return(result);
        }