Need help with an algorithm (674391)

Hi Guys, i try to move an object over a grid. The problem is that between the points i am getting very short stuttering. So i thought i would need to find lines in my point list Like that:

List<Point2> sample = new List<Point2>()
            {
                new Point2(5,5),
                new Point2(4,5),
                new Point2(3,5),
                new Point2(3,4),
                new Point2(3,3),
                new Point2(2,3)
            };

            // this is what the algorithim needs to return me ==>
            List<List<Point2>> result = new List<List<Point2>>();
            result.Add(new List<Point2>() { new Point2(5, 5), new Point2(4, 5), new Point2(3, 5) });
            result.Add(new List<Point2>() { new Point2(3, 5), new Point2(3, 4), new Point2(3, 3) });
            result.Add(new List<Point2>() { new Point2(3, 3), new Point2(2, 3) });

            /////////////////////////////////////////////////
            List<Point2> sample2 = new List<Point2>()
            {
                new Point2(1,2),
                new Point2(2,2)
            };

            // this is what i need ==>
            List<List<Point2>> result2 = new List<List<Point2>>();
            result.Add(new List<Point2>() { new Point2(1, 2), new Point2(2, 2) });

Maybe anyone has the time to help me out here.

Are you looking for tweening to go between these points smoothly? There’s lots of free tweening packages in the asset store, each with its strengths and weaknesses.

Well i solved the problem myself:

public static List<List<Point2>> LineFinder(List<Point2> sample)
        {
            Point2 startingP = new Point2(-1, -1);
            int pointInLine = 0;
            List<Point2> current = new List<Point2>();
            Point2.Direction currentDirection = Point2.Direction.Undefined;
            List<List<Point2>> result = new List<List<Point2>>();

            for (int i = 0; i + 1 < sample.Count; i++)
            {
                // start a new Line
                if (pointInLine == 0)
                {
                    pointInLine++;

                    current = new List<Point2>
                    {
                        sample[i],
                        sample[i + 1]
                    };

                    result.Add(current);

                    currentDirection = (sample[i] - sample[i + 1]).ToDirection();

                    if (currentDirection == Point2.Direction.Undefined)
                    {
                        pointInLine = 0;
                    }
                }

                // start a new Line
                if (pointInLine != 0)
                {
                    pointInLine++;

                    if (sample.Count - 1 < i + 2)
                    {
                        break;
                    }
                    else
                    {
                        Point2.Direction p2d = (sample[i + 1] - sample[i + 2]).ToDirection();

                        if (p2d == currentDirection)
                        {
                            current.Add(sample[i + 2]);
                        }
                        else
                        {
                            pointInLine = 0;
                        }
                    }
                }

            }

            return result;
        }