示例#1
0
    void SeekNextTargetAtRandom()
    {
        AIPathNode[] adjNodes = targetPathNode.GetAdjacentNodes();
        Assert.IsNotNull(adjNodes);

        targetPathNode = adjNodes[Random.Range(0, adjNodes.Length)];
        Assert.IsNotNull(targetPathNode);
    }
示例#2
0
    bool NodePositionsSame(AIPathNode curr, AIPathNode iter)
    {
        if (curr.transform.position.x == iter.transform.position.x && curr.transform.position.z == iter.transform.position.z)
        {
            return(true);
        }

        return(false);
    }
示例#3
0
        // TODO: separate loading for data edited by MonoAGS version
        private static void loadAIPathsData(TrackAIData data, string assetpath, Size trackSize)
        {
            Stream s = File.OpenRead(assetpath + "aipaths.dat");

            if (s == null)
            {
                return;
            }

            List <AIPathNode> paths   = new List <AIPathNode>();
            AGSFileReader     f       = new AGSFileReader(s);
            int        firstNodeIndex = f.ReadInt();
            int        lastNodeIndex  = f.ReadInt();
            int        n    = firstNodeIndex;
            AIPathNode last = null;

            do
            {
                int x = f.ReadInt();
                int y = f.ReadInt();
                // NOTE: since MonoAGS has Y axis pointing up, we need to invert one read from AGS file
                y = trackSize.Height - y;
                AIPathNode node = new AIPathNode();
                node.pt        = new Vector2(x, y);
                node.radius    = f.ReadInt();
                node.threshold = f.ReadInt();
                node.speed     = f.ReadInt();
                int p = f.ReadInt();
                n = f.ReadInt();
                if (last != null)
                {
                    node.prev = last;
                    last.next = node;
                }
                last = node;
                paths.Add(node);
            }while (n != firstNodeIndex);
            // Bind last node to the first one
            if (last != null)
            {
                last.next     = paths[0];
                paths[0].prev = last;
            }

            data.AIPathNodes = paths;
        }
示例#4
0
    // Use this for initialization
    void Start()
    {
        // Debug
        target     = GameObject.Find("Target").transform.position;
        targetNode = GameObject.Find("Target").transform.FindChild("TargetNode").GetComponent <AIPathNode> ();
        NodeList.Nodes.Add(targetNode);
        // ------------------------------
        characterRadius = 1f;
        jumpvector      = new Vector3(0f, jumpHeight, 0f);
        control         = this.GetComponent <AIController> ();
        dash            = this.GetComponent <BurstDash> ();
        // subTargets = new LinkedList<Vector3> ();
        nodeListObject = GameObject.Find("NodeList");

        aiPlayerNode = this.transform.FindChild("PlayerNode").GetComponent <AIPathNode> ();
        // StartCoroutine (CreatePath ());

        Invoke("ChangeTarget", .3f);
    }
示例#5
0
 private bool testShouldChooseNewTarget()
 {
     if (!_targetValid)
     {
         return(true);
     }
     // Choose next path node if inside the check radius for current one, or closer to next one.
     if (_currentNode != null)
     {
         AIPathNode prevNode = _currentNode.prev;
         AIPathNode nextNode = _currentNode.next;
         if (nextNode != null &&
             (prevNode == null || Vectors.Distance(_veh.Position, prevNode.pt) > Vectors.Distance(_currentNode.pt, prevNode.pt)) &&
             Vectors.Distance(_veh.Position, nextNode.pt) < Vectors.Distance(_currentNode.pt, nextNode.pt))
         {
             return(true);
         }
     }
     return(Vectors.Distance(_veh.Position, _targetPos) <= _targetCheckRadius);
 }
示例#6
0
 private bool chooseNewTarget()
 {
     if (_pathNodes != null && _pathNodes.Count > 0)
     {
         if (_currentNode != null && _currentNode.pt != null)
         {
             _currentNode = _currentNode.next;
         }
         else
         {
             _currentNode = _pathNodes[0]; // TODO: find nearest?
         }
         _targetPos         = _currentNode.pt;
         _targetCheckRadius = _currentNode.radius;
         _targetThreshold   = _currentNode.threshold;
         _targetSpeedHint   = _currentNode.speed;
         _targetValid       = true;
     }
     else
     { // TODO??
     }
     return(true);
 }
示例#7
0
    LinkedList <AIPathNode> GetPath(Vector3 target)
    {
        List <AIPathNode>       open   = new List <AIPathNode> ();
        LinkedList <AIPathNode> closed = new LinkedList <AIPathNode> ();

        AIPathNode currentNode = aiPlayerNode;

        closed.AddFirst(currentNode);

        AIPathNode iterNode;

        while (closed.Last.Value != targetNode)
        {
            AIPathNode closestNode = null;
            float      closestDist = Mathf.Infinity;
            for (int i = 0; i < NodeList.Nodes.Count; ++i)
            {
                iterNode = NodeList.Nodes [i];
                if (iterNode != currentNode && !closed.Contains(iterNode) && !NodePositionsSame(currentNode, iterNode))
                {
                    float dist = Vector3.Distance(currentNode.transform.position, iterNode.transform.position);
                    if (dist < closestDist)
                    {
                        closestNode = iterNode;
                        closestDist = dist;
                    }
                }
            }

            closed.AddLast(closestNode);
            currentNode = closestNode;
        }

        closed.RemoveFirst();

        return(closed);

        /*ClearHeuristics ();
         * open.Add (aiPlayerNode);
         *
         * AIPathNode lowestF = aiPlayerNode;
         *
         * while (!closed.Contains (targetNode) && open.Count > 0) {
         *      CalculateHeuristics (open, target);
         *      bool noLowest = true;
         *      for (int i = 0; i < open.Count; ++i) {
         *              if (noLowest || open[i].F < lowestF.F) {
         *                      lowestF = open[i];
         *                      noLowest = false;
         *              }
         *      }
         *
         *      closed.AddLast (lowestF);
         *      open.Remove (lowestF);
         *
         *      print ("Node iterated on: " + lowestF);
         *
         *      AIPathNode iterNode;
         *      for (int i = 0; i < NodeList.Nodes.Count; ++i) {
         *              iterNode = NodeList.Nodes [i];
         *
         *              if (closed.Contains (iterNode) ||
         *                      iterNode == lowestF ||
         *                      !StraightPathPossible (lowestF.transform.position, iterNode.transform.position) ||
         *                      !NextNodeWithinHeight (lowestF.transform.position, iterNode.transform.position) ||
         *                      NextNodeStraightAbove (lowestF.transform.position, iterNode.transform.position)) {
         *                      continue;
         *              }
         *
         *              // print ("-----LOS node: " + iterNode);
         *
         *              if (iterNode == targetNode) {
         *                      closed.AddLast (iterNode);
         *                      iterNode.Parent = lowestF;
         *              } else if (open.Contains (iterNode)) {
         *                      float newG = lowestF.G + Vector3.Distance (iterNode.transform.position, lowestF.transform.position);
         *                      if (newG < iterNode.G) {
         *                              iterNode.Parent = lowestF;
         *                              iterNode.G = newG;
         *                              iterNode.F = iterNode.G + iterNode.H;
         *                      }
         *              } else {
         *                      open.Add (iterNode);
         *                      iterNode.Parent = lowestF;
         *              }
         *      }
         * }
         *
         * if (closed.Count == 0) {
         *      return new LinkedList<AIPathNode> ();
         * }
         *
         * LinkedList<AIPathNode> output = new LinkedList<AIPathNode> ();
         * AIPathNode next = closed.Last.Value;
         * while (next != aiPlayerNode) {
         *      output.AddFirst (next);
         *      next = next.Parent;
         * }
         *
         *
         * return output;
         */
    }
示例#8
0
 // Start is called before the first frame update
 void Start()
 {
     Assert.IsNotNull(m_path);
     targetPathNode = m_path.GetHeadNode();
     Assert.IsNotNull(targetPathNode);
 }