3
\$\begingroup\$

I am working on a game in which a butterfly is flying along some path.

What I am trying to do currently is create a Bezier curve starting from the butterfly's position(previous curves end point) and the rest of the points random for it to fly on. Once it has finished on the curve it needs to continue its path along the next curve that is generated. The problem I have is that the next curve sometimes starts in a direction that makes the transition look rugged and unrealistic. This is the code I have so far.

void updateDirection()
{
    if (!LeanTween.isTweening(this.gameObject))
    {
        Vector3 curveA = { transform.position, new Vector3(Random.Range(-5f, 0), 0, Random.Range(-3f, 0)), new Vector3(Random.Range(-5f, 0), 0, Random.Range(-3f, 0)), new Vector3(Random.Range(-5f, 0), 0, Random.Range(-3f, 0)) };
        LeanTween.move(this.gameObject, curveA, 3f);
    }
}

I am using the LeanTween API to create the movement method easier.

So basically I need to find a way to make a continuous bezier I guess and I am no mathematician so if it could be explained in easy to understand terms that would be amazing!

\$\endgroup\$
2
  • \$\begingroup\$ Reflect the bezier control point to get maximum smoothness. SVG does this for the S and T path commands. This image from the article linked shows it off well. \$\endgroup\$
    – MLM
    Commented Jun 16, 2015 at 4:08
  • \$\begingroup\$ If you use quadratic Bezier curves, you could choose each subsequent point randomly within the circle described in this answer to get smooth transitions that respect some maximum acceleration amount. \$\endgroup\$
    – DMGregory
    Commented Nov 13, 2015 at 13:40

2 Answers 2

1
\$\begingroup\$

You will probably have an easier time with a catmul rom spline. You give points for the path to pass through and it figures out the rest. A catmul rom spline is a type of Hermite spline, which is a different mathematical form of bezier splines. http://www.mvps.org/directx/articles/catmull/

\$\endgroup\$
0
\$\begingroup\$

I guess you could use a trail system much like the one provided for a similar problem:How to approach 360 degree snake without having it "slide"

if you can get the transform of every point of your splines (all of them) you can then add them to a List and use the trail system to traverse them.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .