Beispiel #1
0
        public IEnumerator Move(Transform player, BezierCurve bezierCurve, float speed)
        {
            player.position = bezierCurve.GetPoint(0);
            for (int i = 1; i < bezierCurve.GetPoints().Count;)
            {
                player.position = Vector2.MoveTowards(player.position, bezierCurve.GetPoint(i), Time.deltaTime * speed);

                yield return(new WaitForFixedUpdate());

                if (Vector2.Distance(player.position, bezierCurve.GetPoint(i)) < 0.001f)
                {
                    i++;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Render the lines.
        /// </summary>
        public override void Render(Graphics graphics)
        {
            // Draw the bezier curve.
            Point[] points = bezier.GetPoints();

            foreach (Point point in points)
            {
                graphics.DrawRectangle(pen, point.X, point.Y, 1, 1);
            }

            // Draw control points.
            foreach (Vector2 point in controlPoints)
            {
                graphics.FillEllipse(brush, (float)point.x - 5, (float)point.y - 5, 10, 10);
            }
        }