Example #1
0
        void Update()
        {
            if (!curve.Init())
            {
                return;
            }

            t += Time.deltaTime / duration;
            t %= 1;

            float easedT = EasingFunctions.Linear(t); // you can use any easing function here

            float        arcLength;
            CurveSegment curveSegment = curve.CurveSegmentAtArcLength(easedT * curve.ArcLength(curve.CurveCount()), out arcLength);
            float        curveT       = curveSegment.ComputeTAtArcLength(arcLength);

            transform.position = curveSegment.Evaluate(curveT);
            transform.forward  = curveSegment.EvaluateDv(curveT);
        }
Example #2
0
        public void Run()
        {
            if (m_Graph == null)
            {
                Debug.LogError("The assigned graph is either not assigned or invalid.");
                return;
            }

            // Clear state of previous run
            m_Path.Clear();
            m_Graph.Clear();

            // Convert start and end locations to nodes in the graph
            var start = m_Graph.GetClosestNodeToPoint(m_Start);
            var goal  = m_Graph.GetClosestNodeToPoint(m_End);

            if (start == goal)
            {
                Debug.LogError("Start and goal are the same node. No path was found.");
                return;
            }

            // Create a dictionairy to keep track of how we
            // discovered a node.
            var cameFrom = new Dictionary <Node, Node>();

            // Execute the algorithm we have selected.
            AStarSearch.Execute(m_Graph, start, goal, cameFrom);

            // Initialize the Hermite curve with the path just found
            hermiteCurve = GetComponent <DebugCurve>();
            hermiteCurve.controlPoints = m_Path;
            hermiteCurve.Init();

            // Reconstruct Path
            ReconstructPath(cameFrom, start, goal, m_Path);
        }